仅当满足特定条件(例如,该行上的字段具有特定值)时,才可以在Kendo UI网格中使用行模板吗?如果不满足该条件,则不应渲染模板,而应正常渲染该行。
我不想在模板本身中指定条件,因为除非我误会,否则如果条件不满足,我还必须在模板定义中包括“默认” html。
这是我要实现的示例,但没有用。为简洁起见,我省略了与我的问题无关的其他网格属性:
$("#divGrid").kendoGrid({
rowTemplate: function (data) {
if (condition) kendo.template($("#myRowTemplate").html(data));
// else render row without the template, but how?
}
});
首先,kendo.template
返回一个需要调用的函数(以模板数据作为参数)以返回HTML代码。因此,为使您的示例正常工作,需要进行如下修改:
$("#divGrid").kendoGrid({
rowTemplate: function (data) {
if (condition) {
return kendo.template($("#myRowTemplate").html())(data);
} // else render row without the template, but how?
}
});
现在,不幸的是,由于您已经指定了功能,因此无法“正常渲染行” rowTemplate
。您只能指定在其他情况下需要显示的模板(或字符串):
$("#divGrid").kendoGrid({
rowTemplate: function (data) {
if (condition) {
return kendo.template($("#myRowTemplate").html())(data);
} else {
return '<tr>Normal row</tr>';
// or return kendo.template($("#myRowTemplate2").html())(data)
// or return "<tr>" + data.name + ": " + data.age + "</tr>"
}
}
});
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句