kendo-ui - 在 TreeViewOptions 中使用复选框的 Kendo ui 模板中的参数
问题描述
我正在尝试创建一个创建通用剑道 TreeView 的类,该树可以包含带有复选框的项目和没有复选框的项目。所以,我用流动的 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 的参数“checkable”为 false,那么树中的所有项目都没有复选框。我不知道如何将“checkable”参数传递到模板中。我想要这样的东西:
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 ...
}
}
推荐阅读
- neo4j - 如何在 apoc.load.csv 中指定单独的头文件?
- c# - 使用装箱值类型作为 lock 语句的储物柜是否安全?
- python - 转置 ND 列表列表
- python-3.x - 在 Python3 MacOS 上安装 Cartopy 的问题
- manpage - 如何转义双反斜杠以便我可以在手册页中获得“\\”?
- javascript - 如何将命名导入放入命名空间?
- amazon-web-services - Cognito 登录验证电子邮件未获取用户名
- wordpress - 如何在woocommerce中将电子邮件验证链接移至顶部?
- ios - 将 UICollectionView 连接到 DataSource、使用 Xcode 拖放进行委托以及以编程方式连接之间有什么优缺点
- angular - 包装垫选择选项以适应控件的宽度