在AngularJS元素中注入的任何新元素,需要使用$compile
服务进行编译。编译后的角度指令&作用域变量绑定将起作用。我建议你在loadComplete
事件jqgrid
上编译表格,因为这个事件事件在jqgrid
完全获得渲染时调用,&也会用angular.extend
代替,这将使得代码更具有角度可读性。寻呼机元素在追加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);
});
}
Working Plunkr
希望能帮助您,还需要什么东西,你可以问我任何时候,谢谢。
谢谢你,我会在早上检查一下 - 第一眼看起来很棒! – 2015-04-05 07:21:50
@CameronWilby欢迎您,如果您对此有任何疑问,请告知我,谢谢:) – 2015-04-05 07:22:44
工作完美,谢谢! – 2015-04-07 01:32:10