var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit']);
app.controller('MainCtrl', ['$scope', function ($scope) {
gridOptions1 = {
enableSorting: true,
columnDefs: [
{ name:'firstName', field: 'first-name' },
{ name:'1stFriend', field: 'friends[0]' },
{ name:'city', field: 'address.city'},
{ name:'getZip', field: 'getZip()', enableCellEdit:false}
],
data : [ {
"first-name": "Cox",
"friends": ["friend0"],
"address": {street:"301 Dove Ave", city:"Laurel", zip:"39565"},
"getZip" : function() {return this.address.zip;}
}
]
};
gridOptions2 = {
enableSorting: true,
columnDefs: [
{ name:'firstName1', field: 'first-name1' },
{ name:'1stFriend1', field: 'friends1[0]' },
{ name:'city1', field: 'address1.city'}
],
data : [ {
"first-name1": "Cox1",
"friends1": ["friend1"],
"address1": {street:"301 Dove Ave1", city:"Laurel1", zip:"395651"}
}
]
};
$scope.gridOptions = gridOptions1;
$scope.changeBinding = function(){
$scope.gridOptions = gridOptions2;
}
}]);
.grid {
width: 500px;
height: 250px;
}
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
<script src="http://ui-grid.info/release/ui-grid.js"></script>
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
</head>
<body>
<div ng-controller="MainCtrl">
<div id="grid1" ui-grid="gridOptions" ui-grid-edit class="grid"></div>
<button ng-click="changeBinding()">Change</button>
</div>
</body>
</html>
我目前使用的東西如下。 'self.gridOptions.data = obj [0] .data;''和'self.gridOptions.columnDefs = obj [1] .Data'其中** obj [0] **包含每行的數據和** obj [ 1] **列名稱。我會盡力在我的問題中更清楚。目前正在更新中 – cacev000
我編輯了我的問題,希望更清楚 – cacev000
好的。按照你的說法工作,謝謝。 – cacev000