xml属性数据字段数据网格

发布于 2024-10-21 20:14:55 字数 1192 浏览 3 评论 0原文

为什么我无法为数据字段绑定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羞稚 2024-10-28 20:14:56

您将 dataProvider 设置为 {sampleXML.contact}

它应该是 {sampleXML.contacts}

You set the dataProvider as {sampleXML.contact}

It should be {sampleXML.contacts}

时间海 2024-10-28 20:14:56

您还可以尝试使用 XMLListCollection(如下所示)并将“contactsList”作为数据提供者提供给数据网格。

<mx:XML id="tempXML"
        source="assets/contacts.xml" />

<mx:XMLListCollection id="contactsList"
        source="{tempXML.contacts}" />

假设:xml存储在assets文件夹中,xml名称为contacts.xml

You can also try to use XMLListCollection as shown below and provide 'contactsList' as dataprovider to the datagrid.

<mx:XML id="tempXML"
        source="assets/contacts.xml" />

<mx:XMLListCollection id="contactsList"
        source="{tempXML.contacts}" />

Assumption : xml is stored in assets folder and xml name is contacts.xml

怎会甘心 2024-10-28 20:14:56

如果您想使用相同的 @ 表示法,请尝试将 fx:Model 更改为 fx:XML。模型将 XML 反序列化为对象,这意味着您的 @notation 将不会给出所需的结果。以下示例有效:

<fx:XML 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:XML>

<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>

如果您想使用 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:

<fx:XML 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:XML>

<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>

If you want to use fx:Model then drop the "@" from in front of your dataField names

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文