我试图在条件基础上添加一个特定位置的列..这是代码..在最后位置添加列名...但我想添加列" jkl&# 34;专栏#34; def" ......我将怎么做?通过以下代码,它将列添加到最终位置.....
$scope.columnNames = [
{field: "abc", displayName: $scope.lable_abc, cellTemplate: '<div class="celltemplate" tooltip="{{row.entity.abc}}" tooltip-append-to-body="true" style="padding-left:10px" > {{row.entity.abc}}<div>'},
{field: "def", displayName: $scope.lable_def, cellTemplate: '<div class="celltemplate" title="{{row.entity.def}}" style="padding-left:10px" > {{row.entity.def}}<div>'},
{field: 'ghi', displayName: $scope.lable_ghi, cellTemplate: '<center><div> <img src="{{row.entity.ghi}}" width="20px" ></div></center>', width: 60},
];
if($scope.x == "2" || $scope.y == "3")
{
$scope.columnNames.push({field: "jkl", displayName: $scope.lable_jkl, cellTemplate: '<div class="celltemplate" title="{{row.entity.jkl}}" style="padding-left:10px" > {{row.entity.jkl}}<div>'});
}
答案 0 :(得分:0)
您应该使用如下拼接方法:
$scope.columnNames.splice(2, 0, {field: "jkl", displayName: $scope.lable_jkl, cellTemplate: '<div class="celltemplate" title="{{row.entity.jkl}}" style="padding-left:10px" > {{row.entity.jkl}}<div>'});
'push'方法总是在最后添加。