xml属性数据字段数据网格
为什么我无法为数据字段绑定 xml 属性? (弯曲4)
<fx:Model id="sampleXML">
<contacts>
<contact firstName="Joe" lastName="Smith" emailAddress="[email protected]" />
<contact firstName="Sally" lastName="Lally" emailAddress="[email protected]" />
<contact firstName="Albert" lastName="Rigdon" emailAddress="[email protected]" />
</contacts>
</fx:Model>
<mx:DataGrid dataProvider="{sampleXML.contact}" id="dg">
<mx:columns>
<mx:DataGridColumn headerText="First Name" dataField="@firstName" />
<mx:DataGridColumn headerText="Last Name" dataField="@lastName" />
<mx:DataGridColumn headerText="Email Address" dataField="@emailAddress" />
</mx:columns>
</mx:DataGrid>
Why cannot I bind xml attribute for datafield? (flex 4)
<fx:Model id="sampleXML">
<contacts>
<contact firstName="Joe" lastName="Smith" emailAddress="[email protected]" />
<contact firstName="Sally" lastName="Lally" emailAddress="[email protected]" />
<contact firstName="Albert" lastName="Rigdon" emailAddress="[email protected]" />
</contacts>
</fx:Model>
<mx:DataGrid dataProvider="{sampleXML.contact}" id="dg">
<mx:columns>
<mx:DataGridColumn headerText="First Name" dataField="@firstName" />
<mx:DataGridColumn headerText="Last Name" dataField="@lastName" />
<mx:DataGridColumn headerText="Email Address" dataField="@emailAddress" />
</mx:columns>
</mx:DataGrid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将 dataProvider 设置为 {sampleXML.contact}
它应该是 {sampleXML.contacts}
You set the dataProvider as {sampleXML.contact}
It should be {sampleXML.contacts}
您还可以尝试使用 XMLListCollection(如下所示)并将“contactsList”作为数据提供者提供给数据网格。
假设:xml存储在assets文件夹中,xml名称为contacts.xml
You can also try to use XMLListCollection as shown below and provide 'contactsList' as dataprovider to the datagrid.
Assumption : xml is stored in assets folder and xml name is contacts.xml
如果您想使用相同的 @ 表示法,请尝试将 fx:Model 更改为 fx:XML。模型将 XML 反序列化为对象,这意味着您的 @notation 将不会给出所需的结果。以下示例有效:
如果您想使用 fx:Model,则删除 dataField 名称前面的“@”
Try changing your fx:Model to fx:XML if you want to use the same @ notation. Model deserialises the XML into an object which means your @notation will not give the desired outcome. The following example works:
If you want to use fx:Model then drop the "@" from in front of your dataField names