`

Get Object or Associative array's length

阅读更多

If you need to find the length of an object, and I mean the number of children of the specified object, use the following function/method:

public static function getLength(o:Object):uint
{
    var len:uint = 0;
    for (var item:* in o)
        if (item != "mx_internal_uid")
            len++;
    return len;
}

 

In Flex there is no method to get the length of an object and if you look at an object or an associative array in debugging mode you’ll that length property is not present or is 0 for associative arrays.

I know that there are different ways of arranging data in indexed array structures to have the length property but sometimes maybe you want to know if the object has at least a child or how many children it has.

There is another issue… some arrays/objects used mostly as data providers do get an internal property called mx_internal_uid, so you may not want to count that as a child:

if (item != "mx_internal_uid")

 

More about mx_internal_uid here (livedocs) and in a future article.

 

转载自 : http://www.flexer.info/2008/07/31/how-to-find-an-objects-length/

分享到:
评论

相关推荐

    associative-array

    var AssociativeArray = require ( 'associative-array' ) ; var arr = new AssociativeArray ( ) ; arr . push ( 'key' , { value : 'value' } ) ; arr . push ( 'key2' , { value : 'value2' } ) ; arr . push ( '...

    PHP Arrays Single, Multi-dimensional, Associative and Object Arrays in 无水印原版pdf

    PHP Arrays Single, Multi-dimensional, Associative and Object Arrays in PHP 7 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如...

    Associative array Delphi class-开源

    这意味着你可以存储任何继承自`TObject`的自定义对象实例,如表单、组件或其他面向对象的实体。这为数据存储提供了极大的灵活性,可以根据需求存储不同类型的数据对象。 4. **开源软件**: 这个Delphi类是开源的,...

    ASP Associative Array Class-开源

    一个 ASP 类,可以像在 PHP 中一样创建简单的关联数组; 您可以以编程方式管理任何结构化数据; 该类还提供了从 MySQL 或 MSAccess 数据库加载数据或将关联数组导出到 XML 的方法。

    Cell-Object-Associative-Memory:探索想法

    单元对象关联记忆 探索想法 每个单元格都可以像杰森一样 它们是类似Lua表的关联记忆。 json是关联内存或表的实际字符串表示形式。 但是,出于讨论目的,Json仅被视为与关联存储器或lua表相同,后者可以转换为字符串...

    Multi-Label Lazy Associative Classification

    multi-label lazy associative classifier, which progressively exploits dependencies among labels. Further, since in our lazy strategy the classification model is in- duced on an instance-based fashion,...

    Apress.PHP.Arrays.Single.Multi-dimensional.Associative.and.Object.Arrays.

    Apress.PHP.Arrays.Single.Multi-dimensional.Associative.and.Object.Arrays.in.PHP.7.1484225554.rar 最新书籍,精讲PHP数组,文字版PDF

    Oracle数组的使用

    这里主要涉及了两种类型的数组:`VARRAY` 和 `ASSOCIATIVE ARRAY`(也称为 `INDEXED TABLE`)。接下来,我们将详细解释这些概念,并提供一些实际应用场景。 ### Oracle 数组类型 #### VARRAY (Variable Array) `...

    C++ API for the JSON object interchange format

    CAJUN* is a C++ API for ... name/value pairs, associative array, etc.); it humbly leaves text markup to XML. It is ideal for storing persistent application data, such as configuration or user data files.

    Multidimensional Binary Search Trees Used for Associative Searching

    1975年,来自斯坦福大学的Jon Louis Bentley在ACM杂志上发表的一篇论文:Multidimensional Binary Search Trees Used for Associative Searching 中正式提出和阐述的了把空间划分为多个部分的k-d树。

    Android中的JSON详细总结

    1、JSON(JavaScript Object... – Json.org 2、JSON的结构: (1) Name/Value Pairs(无序的):类似所熟知的Keyed list、 Hash table、Disctionary和Associative array。在Android平台中同时存在另外一个类”Bundle

    PHP.Arrays.in.PHP.7

    Gain an in-depth understanding of PHP 7 arrays. After a quick overview of PHP 7, each chapter concentrates on single, multi-dimensional, associative, and object arrays. ...

    javascript 有趣而诡异的数组

    在这个例子中,`associative_array.length`始终为0,因为数组的`length`属性仅计算基于数字的索引,不包括以字符串为键的元素。因此,即使数组中存在多个键值对,`length`依然显示为0。如果需要存储键值对,最佳做法...

    Associative Learning from Replayed Experience

    首先,标题“Associative Learning from Replayed Experience”揭示了该文档与强化学习(Reinforcement Learning)以及经验回放(Experience Replay)方法的关联。经验回放是深度强化学习(Deep Reinforcement ...

    graphcut系列-其他文献1

    Associative hierarchical CRFs for object class image segmentation2009.pdf Automatic segmentation for semantic objects from multiview images2008.pdf Automatic Segmentation of Background Defocused ...

    json C语言 接口函数

    这种结构在不同语言中有着不同的叫法,比如对象(object)、记录(record)、结构(struct)、字典(dictionary)、哈希表(hash table)、有键列表(keyed list)或关联数组(associative array)。 - **值的有序...

    Oracle Database 12c PL-SQL programming

    Work with collections, varrays, tables, and associative array collections Locate and repair errors and employ exception handlers Execute black box, white box, and integration tests Configure and ...

    systemVerilog的联合数组例子

    1. 使用 associative array 类型:SystemVerilog提供了 associative array 类型,可以使用关键字“assoc”来声明。 2. 使用动态数组:SystemVerilog提供了动态数组,可以使用关键字“dynamic”来声明。 3. 使用 User...

    联想记忆神经网络(Associative Memory)

    联想记忆神经网络(Associative Memory)是一种基于神经网络模型的记忆存储和回忆系统,主要用途是分类和模式识别。在联想记忆中,存储了一系列的模式对(或称为样本对),每个模式对由两个相关的向量组成,通常表示...

    基于神经元网络和 Linear Auto-Associative memory 和pca的人脸识别程序。.zip

    在本项目中,我们探讨了如何使用神经元网络、线性自关联记忆(Linear Auto-Associative Memory, LAAM)以及主成分分析(Principal Component Analysis, PCA)进行人脸识别。这是一项涉及深度学习与特征提取技术的...

Global site tag (gtag.js) - Google Analytics