ps0*_*604 2 kendo-ui angularjs
在这个 plunk 中,我有一个 AngularJS KendoGrid,其中包含两列:代码和名称。代码是一个数字,名称是代码的函数:getName(code)。我将该函数放入模板中,但是我得到了function undefined. 有任何想法吗?
超文本标记语言
<div kendo-grid="grid"
k-data-source="ds"
k-options="gridOptions"></div>
Run Code Online (Sandbox Code Playgroud)
JavaScript
var app = angular.module("app", [ "kendo.directives" ]);
function MyCtrl($scope) {
$scope.gridOptions = {
columns: [
{
field: "code"
},
{
field: "name",
template: '#= getName(code) #'
}]
};
var getName = function(code) {
return "This code is " + code;
};
$scope.ds = [{ code: 1 },
{ code: 2 },
{ code: 3 },
{ code: 4 },
{ code: 5 }];
}
Run Code Online (Sandbox Code Playgroud)
您可以使用角度模板表达式,例如{{ }}以及剑道表达式,例如#= #. 对于你的例子尝试:
$scope.gridOptions = {
columns: [
{ field: "code" },
{
field: "name",
template: '{{ getName(dataItem.code) }}'
}
]
};
$scope.getName = function(code) {
return "This code is " + code;
};
Run Code Online (Sandbox Code Playgroud)
请参阅此演示:http://dojo.telerik.com/@pesho/iMASa/2