我在 angularjs 应用程序中有一个视图,我希望在其中允许用户在各种不同配置的网格之间进行选择。理想情况下,我想将传递给 ng-grid 指令的值绑定到模型变量,如下图所示。但是,尽管此示例呈现的标记在将简单字符串值传递给 ng-grid 时有效(即<div class="gridStyle" ng-grid="gridOptions1"></div>
,动态配置失败。
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.option;
$scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
$scope.gridOptions1 = { data: 'myData',
columnDefs: [{ field:"name", displayName: "NAME"},
{ field:"age", displayName: "AGE"}],
multiSelect: true };
$scope.gridOptions2 = { data: 'myData',
columnDefs: [{ field:"name", displayName: "Name"},
{ field:"age", displayName: "Age"}],
multiSelect: false };
});
<body ng-controller="MyCtrl">
<label>Show me:</label>
<input type="radio" name="option" ng-model="option" value="gridOptions1">Grid A</input>
<input type="radio" name="option" ng-model="option" value="gridOptions2">Grid B</input>
<div class="gridStyle" ng-grid="{{option}}"></div>
</body>
谁能告诉我是否有办法让 ng-grid 动态接受不同的配置,或者是否有解决此限制的方法?请注意,我需要重新配置网格的多个属性,而不仅仅是我认为有解决方法的columnDefs
和属性。data