首页 > 技术文章 > 新手初用angular之双ng-repeat嵌套

YmmY 2017-05-02 13:42 原文

<table id="tb_1" cellspacing="0" cellpadding="2" width="100%" border="1">
    <thead>
        <th ng-repeat="hd in headList">{{hd.name}}</th>
    </thead>
    <tbody> 
         <tr ng-repeat="data in tableData">
            <td ng-repeat="hd in headList">
                <input type="text" ng-model="data[hd.code].value" />
            </td>
        </tr> 
     </tbody> 
</table> 

 

两个ng-repeat当然得有两个数组对象

var head = [
    {code:"packageCounts"},
    {code:"volume"},
    {code:"volumeUnit"},
]
var tableData = [
    {
        packageCounts:{name:"包装件数",value:'1'},
        volume:{name:"体积(方)",value:'2'},
        volumeUnit:{name:"体积单价",value:'3'}
    }
]

 

推荐阅读