gpt4 book ai didi

javascript - 使用 Angular 从 JSON 调用单个结果

转载 作者:行者123 更新时间:2023-11-30 17:38:32 25 4
gpt4 key购买 nike

我正在尝试使用 json 来填充带 Angular html 页面,现在我将其作为我的 JSON:

  [{"listType":"custprof", "prof":"Turkish Government"},
{"listType":"custprof", "prof":"Eren Isaat"},
{"listType":"custprof", "prof":"Mardin, Turkey"},
{"listType":"custprof", "prof":"Canal Irigation channel"},
{"listType":"situation","sit":"Grade Checking limited to working day"},
{"listType":"situation", "sit":"5 grade checkers per machine"},
{"listType":"situation","sit":"Terrain slows accurate grading"},
{"listType":"situation", "sit":"Fine grading requierd multiple passes"},
{"finalImage":"img", "foo":"imgname"}]

这是我的html代码

 <div ng-repeat="case in case_select" ng-show="case.listType =='custprof'" >
<ul>
<li >{{case.prof}}</li>
</ul>
</div>
<h1>Situation</h1>
<div ng-repeat="case in case_select" ng-show="case.listType== 'situation'">
<ul>
<li>{{case.sit}}</li>
</ul>
</div>
</div>
</div>

现在我正在使用 ng-repeat 和 ng-show 从 JSON 文件中获取特定的字符串。我想知道是否有更好/更直接的方法从 JSON 返回特定结果,而不是遍历整个事物并隐藏特定项目。例如,可能看起来像这样:

 <div>{{case.finalImage.foo}}</div>

最佳答案

也许是 filter

 <div ng-repeat="case in case_select | filter: {listType:custprof}" >
<ul>
<li >{{case.prof}}</li>
</ul>
</div>
<h1>Situation</h1>
<div ng-repeat="case in case_select | filter: {listType:situation}">
<ul>
<li>{{case.sit}}</li>
</ul>
</div>

关于javascript - 使用 Angular 从 JSON 调用单个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21536707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com