[英]conditional template kendo ui
仅当满足特定条件(例如,该行上的字段具有特定值)时,才可以在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>"
}
}
});
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.