javascript - AngularJS - 如何过滤嵌套的 json 数组

标签 javascript angularjs json

这里是 AngularJS 新手。这是我一直在处理的 JSON 文件,我想做的是使用 AngularJS 按成分过滤搜索。请帮忙?

{
    "id": 01,
    "recipe-name": "Fried Fish",
    "ing": {
        "i1": "1 fish",
        "i2": "1 egg",
        "i3": "1\/2 cup flour",
        "i4": "salt and pepper",
        "i5": "chili leaves"
    }
}

这是我的过滤结果代码

    <div class="results" ng-repeat="r in recipes | filter:q.ing">

最佳答案

您不需要过滤器。

您只需通过 recipes.ing 嵌套对象进行 ng-repeat 即可。

<div class="results" ng-repeat="r in recipes.ing">
    <p>{{r}}</p>
</div>

简单的 fiddle :http://jsfiddle.net/zq39zspc/1/

关于javascript - AngularJS - 如何过滤嵌套的 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34904585/

相关文章:

javascript - 在 React 中从数组 onClick 创建的样式化 div

angularjs - Protractor:测试窗口滚动行为

javascript - 如何更改 Angularjs 可编辑文本/文本区域行为?

iphone - JSON 提取到 iOS 应用程序

javascript - 如何通过 react-navigation 在 react-native 上使用 react 钩子(Hook)

javascript - 使用 AJAX 时阻止跨域请求

javascript - 将功能从服务器传递到客户端

javascript - 使用 AngularJS/Javascript 仅禁用浏览器后退按钮导航(而不是应用程序中的链接)

JavaScript 数组迭代

android - JSON 数组到 GridView 中的 ImageView