【问题标题】:How to get all values from elements "name" from my JSON-file in my list "StandardListItem"?如何从列表“StandardListItem”中的 JSON 文件中的元素“名称”中获取所有值?
【发布时间】:2017-08-31 09:07:03
【问题描述】:

在我的 view.xml 中,我创建了一个列表和 StandardListItem 元素,我想在其中显示我的 json 文件中的所有名称(名称)。

    <List id="fbl" visible="false" headerText="Fussballer" items="{path: 'fbdetails>/'}">

        <StandardListItem title="{fbdetails>/1/name}"/>
    </List>

这是我的 JSON 文件:

[
{
id: "1",
name: "Kahn",
vorname: "Oliver",
trikotNr: "1",
club: "Bayern München"
},
{
id: "2",
name: "Müller",
vorname: "Thomas",
trikotNr: "9",
club: "Bayern München"
},
{
id: "3",
name: "Ronaldo",
vorname: "Cristiano",
trikotNr: "3",
club: "Real Madrid"
},
{
id: "4",
name: "Messi",
vorname: "Lionel",
trikotNr: "10",
club: "Barcelona"
}
]

输出应该是:

大乱斗

  • 卡恩
  • 穆勒
  • 罗纳尔多
  • 梅西

但是,我得到了这个列表: List

我确信问题出在我的 View.xml 文件中的以下行:

<StandardListItem title="{fbdetails>/1/name}"/>

如何进行迭代以获取所有名称,而不是在仅采用索引 1 名称的路径中写入 /1/?

如果您需要更多详细信息,请询问。我希望有人可以帮助我..

问候

【问题讨论】:

    标签: json xml user-interface model-view-controller view


    【解决方案1】:

    你可以这样尝试。请注意语法

    <List id="fbl" visible="false" headerText="Fussballer" items="{path: 'fbdetails >/'}">
      @for(var i = 10; i < 21; i++)
      {
          <StandardListItem title="{fbdetails>/1/name}"/>
      }
    </List>
    

    【讨论】:

      【解决方案2】:

      我不知道您使用的是什么 GUI 框架,但从这个角度来看,我想说您可以这样:

      <List id="fbl" visible="false" headerText="Fussballer" items="{path: 'fbdetails>/'}">
      
          <StandardListItem title="{fbdetails>/name}"/>
      </List>
      

      或者您可以使用@for

      但是,如果您提供有关您正在使用的框架的更多详细信息,我可以为您提供更好的帮助。

      【讨论】:

        猜你喜欢
        • 2010-10-25
        • 1970-01-01
        • 1970-01-01
        • 2022-08-03
        • 2013-09-12
        • 2011-10-10
        • 2020-04-01
        • 2020-10-25
        • 2020-07-27
        相关资源
        最近更新 更多