2017-08-03 56 views
0

我想從UI網格cellTemplate調用一個javascript函數,將一些行的實體值作爲參數傳遞。將UI網格行數據綁定到單元格中的javascript調用

如果我直接從href調用函數,它會得到前面的'unsafe'。

如果我把它從onclick屬性不正確地綁定(儘管沒有得到不安全的預謀。)

我應該如何稱呼它,並將它正確綁定?

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>' }, 
] 

角1.5.0 UI網格4.0.6

回答

1

我會嘗試包裹無論..LoadDoc()功能應該是在你的控制器的功能,並設置模板是這樣的:

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

在loadDocFunction()中,您可以直接從控制器獲取selectedPayer.PayerRef,並根據需要進行操作。

我不是很清楚什麼javascript:apci:LoadDoc()是,所以很難更精確地說明如何很好地包裝它。

角度包裝模式的一個簡單示例是angular-socket-io

相關問題