2015-10-05 78 views
0

我构建内部的一个HTML模板for循环,我想在对模板传递变量值,并建立动态模板。在JavaScript构建HTML模板循环

下面是我的for循环,我需要colIndex值提到HTML的标签跨度要传递“极品colIndex这里”

for (var colIndex = 0; colIndex < colCount; colIndex++) { 
    $scope.gridOptions.columnDefs.push({ 
    name: 'col-' + colIndex, 
    aggregationType: uiGridConstants.aggregationTypes.sum, 
    width: 85, 
    treeAggregationType: uiGridTreeViewConstants.aggregation.SUM, 
    cellTemplate: '<div class="ui-grid-cell-contents">'+ 
        '<span ng-if="!(row.entity[\'$$\' + col.uid])">{{row.entity[\'col-'+'<<Need colIndex here>>'+'\'] CUSTOM_FILTERS}}</span>'+ 
        '<span ng-if="row.entity[\'$$\' + col.uid]"> {{row.entity["$$" + col.uid].value CUSTOM_FILTERS}}</span>'+ 
        '</div>' 
    }); 
} 

请建议。

+1

难道你们就不能只是通过它在你填充'name'属性以同样的方式? –

+0

我想更复杂的东西和得到基本字符串连接;)... –

回答

0

你可以做到这一点,

for (var colIndex = 0; colIndex < colCount; colIndex++) { 
$scope.gridOptions.columnDefs.push({ 
name: 'col-' + colIndex, 
aggregationType: uiGridConstants.aggregationTypes.sum, 
width: 85, 
treeAggregationType: uiGridTreeViewConstants.aggregation.SUM, 
cellTemplate: '<div class="ui-grid-cell-contents">'+ 
       '<span ng-if="!(row.entity[\'$$\' + col.uid])">{{row.entity[\'col-'+colIndex+'\'] CUSTOM_FILTERS}}</span>'+ 
       '<span ng-if="row.entity[\'$$\' + col.uid]"> {{row.entity["$$" + col.uid].value CUSTOM_FILTERS}}</span>'+ 
       '</div>' 
}); 
} 
+0

呀:d ..我意识到张贴后的问题,这是非常愚蠢的问题要问:)谢谢猪头.. –