javascript - Angular JS NG-子数组中的重复

标签 javascript angularjs

我需要对子数组(数组的元素内部)执行 ng-repeat。这是数据;

{familyName:'Vodka', familyCode:'1', hasPremium: '1', families: [
    { subFamilyName: 'Best', products: [
        { title: 'Grey goose 70 cl', price: '400', cant: '0', premium: '1' },
        { title: 'Grey goose 1,5l', price: '875', cant: '0', premium: '0' }
    ]},
    { subFamilyName: 'Poor', products: [
        { title: 'Grey goose 10 cl', price: '40', cant: '0', premium: '0' },
        { title: 'Grey goose 17,5l', price: '85', cant: '0', premium: '0' }
    ]}
]},
{familyName:'Rum', familyCode:'1', hasPremium: '1', families: [
    { subFamilyName: 'Best', products: [
        { title: 'Grey goose 70 cl', price: '400', cant: '0', premium: '1' },
        { title: 'Grey goose 1,5l', price: '875', cant: '0', premium: '0' }
    ]},
    { subFamilyName: 'Poor', products: [
        { title: 'Grey goose 10 cl', price: '40', cant: '0', premium: '0' },
        { title: 'Grey goose 17,5l', price: '85', cant: '0', premium: '0' }
    ]}
]

完美。我的 $scope 中有一个名为 selectedFamily 的变量,它保存出于导航目的而选择的家庭代码。现在,在 a 中,我需要打印所选系列的子系列(在 selectedFamily var 中编码)以及每个子系列的产品。

我在想如何过滤并执行 ng-repeat。

最佳答案

这是适合您的解决方案

<li ng-repeat="item in items">
                <input type="text" ng-model="item.familyName" />
                <input type="text" ng-model="item.familyCode" />
                <ul>
                    <li ng-repeat="subItem in item.families">{{subItem.subFamilyName}}
                        <div ng-repeat="subSubItem in subItem.products">
                            <input type="text" ng-model="subSubItem.title" />
                            <input type="text" ng-model="subSubItem.price" />
                        </div>
                    </li>
                </ul>
            </li>

你可以看看这个 fiddle http://jsfiddle.net/1ncubt8v/

关于javascript - Angular JS NG-子数组中的重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802877/

相关文章:

javascript - 如何更改 Angular 值配方中的存储值

html - 整个 Controller 在函数调用中被调用

javascript - 带有 ObjectId 的 Mongoose 中的嵌套数组

javascript - deviceready 不开火 Cordova

javascript - 我需要将空参数传递给 JavaScript 函数吗?

javascript - angularjs日期时区调整问题

javascript - Angular js中的自定义过滤器

angularjs - ng-show/-hide 的替代方案或如何仅加载 DOM 的相关部分

javascript - 方法不是函数

javascript - 多个异步 ajax 调用 : How do I execute a function after ALL calls resolve even if some fail?