【发布时间】:2016-02-02 08:36:30
【问题描述】:
(对不起,如果这是重复的,但我发现 not 回答了我的问题: Databinding is not working with kendo grid in angular JS directives )
我正在尝试使用包含剑道网格的 templateUrl 创建一个指令,并在控制器中使用该指令。
我可以设法绑定一些指令的属性(例如 my-grid-options,它在控制器中初始化)但 不能 my-grid-id em>。
我错过了什么? (完整的 plunk here)
指令:
Directives.myGrid = function() {
return {
scope: {
myGridId: "=",
myGridOptions: "="
},
restrict: "E",
transclude: true,
templateUrl: 'myGrid.html',
link: function(scope) {
//... some code using the myGridId
scope.myGridId.....
}
}
}
myGrid.html:
<div kendo-grid="myGridId" k-options="myGridOptions" id="myGridId">
</div>
我想如何使用它:
<body ng-app='app' ng-controller='myCtrl'>
<my-grid my-grid-id="mainGrid" my-grid-options="mainGridOptions"></my-grid>
</body>
控制者:
angular.module('app').controller('myCtrl',function($scope){
$scope.ds = [
{Category:"Toys", Name: "Doll", Code: "p1", Special: false},
....
{Category:"Stationary", Name: "Crayons", Code: "p4", Special: false}
];
$scope.mainGridOptions = {
columns: [
{
field: "Category",
title: "Category"
},
{
field: "Name",
title: "Name"
},
{
field: "Code",
title: "Code"
},
{
field: "Special",
title: "Special Offer"
},
],
dataSource: $scope.ds,
sortable: true,
selectable: true,
resizable: true,
pageable: true,
reorderable: true,
columnReorder: function (e) {
//do something trivial... for example sake, but a more complex event is used
$.each($scope.mainGrid.wrapper.find('tbody tr'), function () {
var model = $scope.mainGrid.dataItem(this);
if (model.Special === true) {
$(this).addClass('special-row');
}
});
}
};
});
感谢您的建议。
【问题讨论】:
-
这可能是我愚蠢的匆忙,但我在控制器的任何地方都看不到 $scope.mainGrid 变量。但是,您确实尝试使用属性“my-grid-id”将其绑定到您的指令...
-
@ocket-san 我正在尝试通过指令中的 kendo-grid 生成它。如果我直接使用 kendo-grid 而不是带有 kendo-grid 的指令,看看它是如何工作的
-
好的。另外,我试图查看您的 plunkr 链接,但每次都超时。你能解决这个问题,这样我才能看得更清楚吗? tnx
-
@ocket-san 它对我有用,但我现在也冻结了它并从其他人那里检查并且也有效。你能再试一次吗?谢谢
标签: angularjs kendo-grid