嵌套的ng-Repeat不工作angularJS

时间:2014-10-09 05:34:44

标签: javascript angularjs

我的代码就像这样

<table ng-app='myApp'>
    <thead>

    </thead>
    <tbody ng-controller="MainCtrl">
        <tr ng-repeat="prdElement in palletElement">
            <td>{{prdElement.name}}</td>
            <tr ng-repeat="data in prdElement.data">

                <td>
                    {{data.itemId}}
                </td>
                <td>
                    {{data.shipmentId}}
                </td>
                <td>
                    {{data.itemCode}}
                <td>
                    {{data.description}}
                </td>

                <td>
                    {{data.handlingUnit}}
                </td>
                <td>
                    {{data.weight}}
                </td>
                <td>
                    {{data.class}}
                </td>
                <td>
                    {{data.lenght}}
                </td>

                <td>
                    {{data.width}}
                </td>
                <td>
                    {{data.height}}
                </td>
                <td>
                    {{data.flag}}
                </td>

                <td>
                    <input type="text" ng-model="prdElement.quantity" placeholder="Code" required />
                </td>

            </tr>
            <tr>
                <td>
                    <button ng-click="newPalletItem(palletElement,$event)">Submit</button>
                </td>
            </tr>
         </tr>

        </tbody>

    </table>


(function () {
    angular.module('myApp', []).controller('MainCtrl', function ($scope) {

        var counter = 0;

        $scope.palletElement =
        [{
            name: 'Pallet 1',
            Data:[{
            name:'item 1' ,
            itemId: '284307',
            shipmentId: 'eb44f690-c97a-40e3-be2a-0449559e171a',
            itemCode: '',
            description: 'Bicycle parts - frame',
            quantity: '31',
            handlingUnit: 'CTN',
            weight: '613.04',
            class:'',
            lenght: '102',
            width: '42',
            height: '61',
            flag:'P'
        }, {
            name: 'item 2',
            itemId: '284308',
            shipmentId: 'eb44f690-c97a-40e3-be2a-0449559e171a',
            itemCode: '',
            description: 'Bicycle parts - fork',
            quantity: '22',
            handlingUnit: 'CTN',
            weight: '242.99',
            class: '',
            lenght: '75',
            width: '34',
            height: '18',
            flag: 'P'
        }]
        }]

    }
    });
}());

一切看起来都没问题,但没有工作,任何人都可以指出我做错了吗?

Fiddle

1 个答案:

答案 0 :(得分:2)

ng-controller="MainCtrl"移除tbody并将其添加到table

prdElement.data更改为prdElement.Data并尝试

请参阅DEMO