我正在构建一个AngularJS应用程序,使用jqGrid来显示建筑物列表。每一行都包含有关该建筑的信息以及两个按钮。
- 链接到详细信息屏幕的编辑按钮
- 一个删除按钮,将从后端数据库中删除建筑
我的目标是通过在jqGrid配置对象上使用formatter
回调将这些按钮添加到网格中,该回调被传递给jqGrid指令。
我遇到的问题是,我似乎无法获得ng-click
绑定来调用我分配给它的函数
我创建了一个plunker来展示我的问题。http://plnkr.co/edit/2UDdNjfwCLauhlw1z3oL?p=preview
如何使此ng-click
绑定按预期工作?
AngularJS元素中注入的任何新元素,都需要使用$compile
服务进行编译。在汇编了angular指令&范围变量绑定将起作用。我建议您编译jqgrid
的loadComplete
事件的表,因为当jqgrid
完全渲染时会调用此事件事件,&用CCD_ 9代替CCD_。Pager元素在附加DOM之前也应该经过编译周期。
指令(链接功能)
link: function(scope, element, attrs) {
scope.$watch('config', function(newValue) {
element.children().empty();
var table = angular.element('<table id="' + newValue.id + '"></table>');
element.append($compile(table)(scope));
angular.extend(newValue, {
jsonReader: {
root: 'Rows',
page: 'Page',
total: 'Total',
records: 'Records',
repeatitems: false
},
viewrecords: true,
rowNum: 15,
loadComplete: function() {
//compiling DOM after table load
$compile(angular.element('#' + newValue.id))(scope);
},
rowList: [15, 30, 50],
altRows: true
});
if (newValue.pager) {
var pager = angular.element('<div id="' + newValue.pager + '"></table>');
element.append($compile(pager)(scope));
angular.extend(newValue, {
pager: '#' + newValue.pager,
pagerpos: "center",
recordpos: "right",
pgbuttons: true,
pginput: true
});
}
angular.element(table).jqGrid(newValue);
});
}
工作Plunkr
希望这能帮助你,仍然需要任何你可以随时问我的事情,谢谢。