我想从 UI-Grid cellTemplate 调用 JavaScript 函数,将行的一些实体值作为参数传递。
如果我直接从 href 调用该函数,则会在前面添加“不安全”。
如果我从 onclick 属性调用它,它不会正确绑定(bind)(尽管没有添加不安全前缀。)
我应该如何调用它并正确绑定(bind)它?
href 尝试:
columnDefs: [
{ name: "DocNumber", cellTemplate: '<a href=\'javascript:apci.LoadDoc("{{grid.appScope.selectedPayer.PayerRef}}")\'>{{row.entity.DocNumber}}</a>' },
]
onclick 尝试:
columnDefs: [
{ name: "DocNumber", cellTemplate: '<a href="#" onclick=\'javascript:apci.LoadDoc("{{grid.appScope.selectedPayer.PayerRef}}")\'>{{row.entity.DocNumber}}</a>' },
]
Angular 1.5.0 UI网格4.0.6
最佳答案
我会尝试包装 ..LoadDoc() 函数应该在 Controller 中的函数中的任何内容,并像这样设置模板:
cellTemplate: '<a ng-click="grid.appScope.loadDocFunction(row.entity)>' +
'{{ row.entity.DocNumber }}' +
'</a>"'
在loadDocFunction()中,您可以直接从 Controller 获取selectedPayer.PayerRef,并按照您的意愿使用它。
我不太清楚 javascript:apci:LoadDoc() 是什么,因此很难更准确地说明如何很好地包装它。
Angular 包装模式的一个简单示例是 angular-socket-io .
关于javascript - 将 UI 网格行数据绑定(bind)到 cellTemplate 中的 javascript 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45482805/