在树视图选项中的复选框的剑道 UI 模板中使用参数



我正在尝试创建一个类来创建通用剑道树视图,该树可以包含带复选框的项目和不带复选框的项目。 因此,我创建了一个带有流动 c'tor 的类:

constructor(checkable: boolean = false) {
// Create the treeview options
const treeViewOptions: kendo.ui.TreeViewOptions = {
checkboxes: {
checkChildren: true,
template: "# if (item.level() > 0) { #" +
"<input type='checkbox' #= item.checked ? 'checked' : '' #>" +
"# } #" 
}, 
// ... The rest of the treeViewOptions ...
}

现在,他们的item.level==0的所有项目都没有复选框。 我希望如果 c'tor 的参数"可检查"为假,那么树中的所有项目都没有复选框。我不知道如何将"可检查"参数传递到模板中。我想要这样的东西:

checkboxes: {
checkChildren: true,
template: "# if (checkable && item.level() > 0) { #" +
"<input type='checkbox' #= item.checked ? 'checked' : '' #>" +
"# } #" 
}, 

请帮助我,如果您认为有更优雅的方法可以做到这一点,我将很高兴听到。 谢谢

您可以将模板设置为匿名函数,并让它根据构造函数参数发出不同的模板字符串。

template: function () {
if (checkable) {
return ... template string that allows checkboxes at item level > 0 ...
} else {
return ... simpler template string that has no checkboxes anywhere ...
}
}

最新更新