ng-repeat a single element over nested objects

前端 未结 4 1508
迷失自我
迷失自我 2020-12-15 08:13

Say I have an object with keys corresponding to products and values corresponding to objects which in turn have keys corresponding to price points at which those products ha

4条回答
  •  粉色の甜心
    2020-12-15 08:44

    Just transform your object to an array... it's pretty easy in JS. Something like:

    $scope.data = { 'widget': { '1': 10, '2': 5 } };
    
    var tableData = [];
    for (item in $scope.data) {
        var thing = item;
        for (subitem in $scope.data[thing]) {
            tableData.push({
                thing: thing,
                price: subitem,
                amount: $scope.data[thing][subitem]
            });
        }
    }
    

    I've created a jsfiddle with this example: http://jsfiddle.net/b7TYf/

提交回复
热议问题