模板中的 if 语句条件格式 kendo 网格列问题
Conditionally formatting kendo grid column issue with if statement in template
我正在 运行 遇到一个问题,试图使用模板向 kendo 网格中我的一列中的值添加百分号,我正在使用的是..
template: "#if(Markup != null){ #=kendo.format('{0:p}', Markup / 100)# }#"
因此,如果标记值不为空,那么我希望它显示百分号,但是当我 运行 网格时,我返回的只是我的列
=kendo.format('{0:p}', Markup / 100)
在这种情况下,我喜欢将模板用作函数:
template: function(item) {
if(item.markup) {
return kendo.format('{0:p0}', item.markup / 100);
}
return item.name;
}
或者您可以按照自己的方式使用它:
template: "#= data.markup ? kendo.format('{0:p}', data.markup / 100): 'N/A' #"
注意:
"#if(Markup != null){ #=kendo.format('{0:p}', Markup / 100)# }#"
\--- this hash closes script,
everithing after that is string.
Thats why you see
=kendo.format('{0:p}', Markup / 100) in grid
我正在 运行 遇到一个问题,试图使用模板向 kendo 网格中我的一列中的值添加百分号,我正在使用的是..
template: "#if(Markup != null){ #=kendo.format('{0:p}', Markup / 100)# }#"
因此,如果标记值不为空,那么我希望它显示百分号,但是当我 运行 网格时,我返回的只是我的列
=kendo.format('{0:p}', Markup / 100)
在这种情况下,我喜欢将模板用作函数:
template: function(item) {
if(item.markup) {
return kendo.format('{0:p0}', item.markup / 100);
}
return item.name;
}
或者您可以按照自己的方式使用它:
template: "#= data.markup ? kendo.format('{0:p}', data.markup / 100): 'N/A' #"
注意:
"#if(Markup != null){ #=kendo.format('{0:p}', Markup / 100)# }#"
\--- this hash closes script,
everithing after that is string.
Thats why you see
=kendo.format('{0:p}', Markup / 100) in grid