我正在尝试为偶数行和奇数行加载两个不同的json数据,就像我们看到 here 一样。我使用 ng-grid 尝试使用多个来源作为参考,但没有任何解决方案。请告诉我同样的可能性。是否可以这样做。
HTML
<div class="list-view-body">
<div class="list-view" ng-grid="settings"></div>
</div>
AngularJS
$scope.settings = {
data: 'records',
enableColumnResize: false,
enablePaging: true,
enableRowSelection: false,
rowHeight: 35,
headerRowHeight: 35,
totalServerItems: 'totalServerItems',
pagingOptions: {
pageSizes: [15, 20, 50, 80, 100],
pageSize:15,
currentPage: 0
},
showFooter: true,
footerRowHeight: 0,
columnDefs: [
{field: 'id', displayName: '', width: 25, cellTemplate: '<a href="javascript:void(0);" class="lv-show-tasks" ng-click="show_campaign_tasks($event);"><span class="caret-right"></span></a>' },
{field: 'reports', displayName: 'Reports', width: 75 },
{field: 'opportunityName', displayName: 'Opportunity', width: 250},
{field: 'proposalId', displayName: 'Proposal ID', width: 95},
{field: 'startDate', displayName: 'Start date', width: 90},
{field: 'endDate', displayName: 'End date', width: 90},
{field: 'amount', displayName: 'Amount', cellTemplate: '<div class="ngCellText"><span>{{row.entity.amount | currency:\'USD$\'}}</span></div>' },
{field: 'alertss', displayName: 'Alerts'},
{field: 'healths', displayName: 'Health'},
{field: 'commentss', displayName: 'Comments' },
{field: 'flag', displayName: 'Flag', cellTemplate: '<div class="ngCellText"><span class="action-icon lv-flag true"></span></div>' }
]
};
答案 0 :(得分:1)
我认为它可以在控制器中混合两个数据json源,插入它们并使用ng-grid指令显示结果......就像这样
// main.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myOddData = [{name: "Moroni Odd", age: 50},
{name: "Tiancum Odd", age: 40},
{name: "Jacob Odd", age: 20},
{name: "Nephi Odd", age: 30},
{name: "Enos Odd", age: 34}];
$scope.myEvenData = [{name: "Moroni Even", age: 51},
{name: "Tiancum Even", age: 43},
{name: "Jacob Even", age: 27},
{name: "Nephi Even", age: 23},
{name: "Enos Even", age: 34}];
$scope.result = $scope.myOddData.reduce(function(arr, v, i) {
return arr.concat(v, $scope.myEvenData[i]);
}, []);
$scope.gridOptions = { data: 'result' };
});
这里是相关的Plunker http://plnkr.co/edit/MyV5pBXK4rQEmbfbCjgL