我已经编写了以下自定义组件SubNavBar.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="100" width="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
[Bindable] public var menuItems:XMLListCollection;
private function init():void
{
trace("SubNav: config = "+menuItems);
}
]]>
</mx:Script>
<mx:HBox y="30" id="menu">
<mx:List dataProvider="{menuItems}"/>
</mx:HBox>
</mx:Canvas>
我使用以下代码在父自定义组件中设置此组件:
<com:SubNavBar id="subNavMenu" menuItems="{subNavConfig}"
x="10" y="-15">
</com:SubNavBar>
只要在init()
中运行trace
函数,属性menuItems
就会返回null
。对于其他变量类型,例如Boolean或String,我似乎没有这个问题。这是由于XMLListCollection对象的大小造成的吗?如何使用XMLListCollection属性设置此SubNavBar自定义组件并将其绑定到组件中的控件?
谢谢!
发布于 2009-12-12 08:03:58
我测试了这段代码,似乎一切都对我有用。您确定正确设置了subNavConfig变量吗?
下面是我使用的客户端代码:
// Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onInit()" xmlns:ns="comp.*">
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
[Bindable]
public var bookCollection:XMLListCollection;
public function onInit():void
{
var books:XML = <books>
<book publisher="Addison-Wesley" name="Design Patterns" />
<book publisher="Addison-Wesley" name="The Pragmatic Programmer" />
<book publisher="Addison-Wesley" name="Test Driven Development" />
<book publisher="Addison-Wesley" name="Refactoring to Patterns" />
<book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
<book publisher="O'Reilly Media" name="Unit Test Frameworks" />
</books>;
var booklist:XMLList = books.book;
bookCollection = new XMLListCollection(booklist);
}
]]>
</mx:Script>
<ns:SubNavBar id="fb" menuItems="{bookCollection}"/>
</mx:Application>
下面是我得到的输出:
SubNav: config = <book publisher="Addison-Wesley" name="Design Patterns"/>
<book publisher="Addison-Wesley" name="The Pragmatic Programmer"/>
<book publisher="Addison-Wesley" name="Test Driven Development"/>
<book publisher="Addison-Wesley" name="Refactoring to Patterns"/>
<book publisher="O'Reilly Media" name="The Cathedral & the Bazaar"/>
<book publisher="O'Reilly Media" name="Unit Test Frameworks"/>
发布于 2009-12-12 07:10:21
也许我遗漏了一些东西,但您将{subNavConfig}设置在哪里?
编辑:
这可能是因为它是如何被casted...try的,比如...
var listcol:XMLListCollection = new XMLListCollection(configXML.destination.(@mapID == mapID).subSections);
https://stackoverflow.com/questions/1891423
复制相似问题