0

我想从 UI-Grid cellTemplate 调用一个 javascript 函数,将一些行的实体值作为参数传递。

如果我直接从 href 调用该函数,它会在前面加上“不安全”。

如果我从 onclick 属性调用它,它不会正确绑定(虽然没有得到 unsafe 前缀。)

我应该如何调用它并正确绑定它?

尝试:

columnDefs: [
    { name: "DocNumber", cellTemplate: '<a href=\'javascript:apci.LoadDoc("{{grid.appScope.selectedPayer.PayerRef}}")\'>{{row.entity.DocNumber}}</a>' },
]

点击尝试:

columnDefs: [
    { name: "DocNumber", cellTemplate: '<a href="#" onclick=\'javascript:apci.LoadDoc("{{grid.appScope.selectedPayer.PayerRef}}")\'>{{row.entity.DocNumber}}</a>' },
]

Angular 1.5.0 UI-Grid 4.0.6

4

1 回答 1

1

我会尝试将 ..LoadDoc() 函数应该包含在控制器中的函数中,并像这样设置模板:

cellTemplate: '<a ng-click="grid.appScope.loadDocFunction(row.entity)>' +
                '{{ row.entity.DocNumber }}' + 
              '</a>"'

在 loadDocFunction() 中,您可以直接从控制器获取 selectedPayer.PayerRef,并按照您的意愿使用它。

我不太清楚javascript:apci:LoadDoc()是什么,因此很难更准确地包装它。

angular 包装器模式的一个简单示例是angular-socket-io

于 2017-08-03T12:27:27.997 回答