apache-flex - 将项目添加到数组

标签 apache-flex actionscript-3

如何将项目添加到多维数组?我想将价格添加到 item2 但我得到“push is not a function”

<fx:Script>
    <![CDATA[

        [Bindable]
        public var dp:Array = [ 
            { label: "item1", desc: "this is item 1"  },
            { label: "item2", desc: "this is item 2"  },
            { label: "item3", desc: "this is item 3"  }
        ];


        private function addItem():void{
            var v:String = '$8.99';
            dp[1].push( ("price:", v ) ); 
            dp.refresh();

        }
    ]]>
</fx:Script>


<mx:VBox> 
    <mx:Repeater id="r" dataProvider="{myAC}">
        <mx:RadioButton label="{r.currentItem.label}"/>
        <mx:Text text="{r.currentItem.desc}"/>
        <mx:Text text="{r.currentItem.price}"/>
    </mx:Repeater>


<s:Button label="push" click="addItem()"/>


</mx:VBox> 


</mx:Application>

最佳答案

您有一个对象数组,而不是数组数组。试试这个:

    [Bindable]
    public var dp:Array = [ 
        { label: "item1", desc: "this is item 1", price : ""  },
        { label: "item2", desc: "this is item 2", price : ""  },
        { label: "item3", desc: "this is item 3", price : ""  }
    ];

    private function addItem():void{
        var v:String = '$8.99';
        dp[1]["price"] = v; 
        dp.refresh();

    }

关于apache-flex - 将项目添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422856/

相关文章:

javascript - 如何访问通过swfobject的embedSWF嵌入的flash对象?

css - 在 Flex 组件中设置不同的图表数据提示样式

flash - ActionScript 2.0中的声音可视化

Haxe 中的 Flash 函数重载

flash - Flash 客户端未收到来自 Node.js 的套接字数据

actionscript-3 - 分别计算mp3长度的旋转

regex - 使用 RegEx 检查扩展名

actionscript-3 - 弹性 : Determine if Space key is held down during MouseEvent

javascript - 类型错误 : Object doesn't support this property or method in IE8/IE9

apache-flex - 需要帮助在 Flex 中设计 TabNavigator 样式