gpt4 book ai didi

javascript - Angular UI Grid : How to bind HTML with the cellTemplate, 并动态构建 ng-click 适用的 HTML

转载 作者:行者123 更新时间:2023-12-05 01:20:54 32 4
gpt4 key购买 nike

根据要求,这是一个 plunker- http://plnkr.co/edit/tIkBFO?p=preview

我正在使用 controllerAs 模式。我一直在使用带有过滤器 ($sce) 的单元格模板进行清理,然后构建 HTML。对于我的生活,我无法让 ng-click 注册到我的 Controller 。

我可以将单元格模板更改为 cellTemplate:'<button ng-click="grid.appScope.user.delete(\'works!\')">X</button>' -> 这行得通。

有没有办法在不使用单元格模板的情况下仍然访问 Controller ?详细信息列是我遇到问题的地方。

感谢阅读!

相关问题- https://github.com/angular-ui/ui-grid/issues/4116

https://github.com/angular-ui/ui-grid/issues/4886

这是代码-

        var user = this;

user.gridDefs = [{
displayName: 'User ID',
name: 'userId',
width: "10%"
}, {
name: 'firstName',
width: "15%"
}, {
name: 'lastName',
width: "15%"
}, {
name: 'email',
cellTemplate: '<div ng-bind-html="COL_FIELD |trustedclean"></div>',
width: "25%"
}, {
name: 'username',
width: "15%"
}, {
name: 'details',
cellTemplate:'<div ng-bind-html="COL_FIELD |trustedclean"></div>'
width: "20%"
}, ];

user.gridData = _.map(dataFromSvc.users, function(user) {
var buildDetailsString = buildDetails(user.uid);
var object = {
'userId': user.Id,
'firstName': user.firstName,
'lastName': user.lastName,
'email': '<a href=\"mailto:' + user.primaryEmail + '\">' + user.primaryEmail + '</a>',
'username': user.uid,
'details': '<div><a href=\"#/viewuser/'+user.uid+'/true\">View</a>/<a ng-click=\"user.deleteUser('+user.uid+')\">Delete</a></div>'
return object;
});

user.deleteUser = function(uid) {
console.log(uid);

};

这是 HTML-

<div id="grid2" ui-grid="{ data: user.gridData, columnDefs:user.gridDefs}" class="grid"></div>

最佳答案

这足以绑定(bind)包含字符串的 html

{ field: 'message', displayName : 'Message Description', cellTemplate: '<div ng-bind-html="COL_FIELD"></div>' }

关于javascript - Angular UI Grid : How to bind HTML with the cellTemplate, 并动态构建 ng-click 适用的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38275993/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com