简体   繁体   English

dijit树+复选框-无法选择/取消选择复选框

[英]dijit Tree + checkbox - unable to select/unselect checkbox

I'm trying to place a checkbox inside dijit.Tree by entering input html code as part of label value. 我试图通过输入输入html代码作为标签值的一部分来在dijit.Tree中放置一个复选框。 And it displays ok but I can't check or uncheck it. 它显示确定,但我无法选中或取消选中它。 As if click events are not bubbling/reaching input element. 好像单击事件没有冒泡/到达输入元素。

Here is how I create my tree object. 这是我创建树对象的方法。

myTree = new dijit.Tree({
    model: myModel,
    showRoot: false,            
    getLabel: function(item) {
        if (!item.root)
            return '<input type="checkbox" name="'+ item.name +'" id="'+ item.name +'" value="1" /> '+ item.name;
    }

}, "gridDiv");

How can I fix this ? 我怎样才能解决这个问题 ?

right now 2 choices come to my mind: 现在我想到2个选择:

  1. Use the new dojo's dgrid if you can. 如果可以,请使用新的dojo的dgrid。 With this new grid you can use the Editor module and pass "checkbox" as a parameter and it would render a checkbox in your column. 有了这个新的网格,您可以使用“编辑器”模块并将“复选框”作为参数传递,它将在您的列中呈现一个复选框。 Check it out here . 在这里查看 Then you can download it here and when you do, check out the "test" folder where you will find an example of what you want in "dgrid/test/tree.html". 然后,您可以在此处下载它并且在执行该操作时,请检出“ test”文件夹,您可以在“ dgrid / test / tree.html”中找到想要的示例。
  2. in your current grid, edit your return statement for getLabel method and make it return a dojo style markup like <div data-dojo-type="dijit.form.CheckBox" ... ></div> and then after the tree's startup event do a dojo.parser.parse(tree.domNode) . 在当前网格中,编辑getLabel方法的return语句,并使其返回dojo样式标记,例如<div data-dojo-type="dijit.form.CheckBox" ... ></div> ,然后在树启动之后事件执行dojo.parser.parse(tree.domNode) This will parse only your grid's DOM node and will convert any dojo style markup into actual dojo objects. 这将仅解析网格的DOM节点,并将任何dojo样式标记转换为实际的dojo对象。

I personally recommend, if you can, the first choice. 如果可以的话,我个人建议第一选择。

Luck, 运气,

I'd go with cbtree if I have check boxes in the tree. 如果树中有复选框,我会选择cbtree。 check here 在这里检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM