简体   繁体   English

jquery kendo-ui 添加属性和 class 到复选框树项目

[英]jquery kendo-ui add attribute and class to checkbox tree item

Where I am appending my dynamic checkbox items within a loop, I tried adding the additional suffix as seen below:我在循环中附加我的动态复选框项目时,我尝试添加额外的后缀,如下所示:

checkBoxTree.append({ text: plc + " (" + id + ")"}).attr("data-id", id).className = "id-item class";

I get no errors, but the attribute and two classes are not added anywhere.我没有收到任何错误,但属性和两个类都没有添加到任何地方。 How Is this done?这是怎么做的?

the attempted above adding this at the end of where I'm writing the new checkbox elems' .attr("data-id", id).className = "id-item class ";'上面尝试在我编写新复选框 elems' .attr("data-id", id).className = "id-item class ";'的末尾添加这个

You should not play with Kendo's DOM, it's constantly redrawn.你不应该玩 Kendo 的 DOM,它会不断地重绘。 I suggest using template and wrapping the item content's inside a div .我建议使用template并将项目内容包装在div中。 Then add any class or data attribute you would need over that div , instead of the item's li .然后在该div上添加您需要的任何 class 或数据属性,而不是项目的li Example:例子:

 <:DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Kendo UI Snippet</title> <link rel="stylesheet" href="https.//kendo.cdn.telerik.com/2020.2.617/styles/kendo.default-v2.min:css"/> <script src="https.//code.jquery.com/jquery-1.12.4.min:js"></script> <script src="https.//kendo.cdn.telerik.com/2020.2.617/js/kendo.all.min.js"></script> </head> <body> <div id="treeview"></div> <script> let tv = $("#treeview"):kendoTreeView({ template. "<div data-id='#= item.id #' class='id-item class'>#= item.text # (#= item,inStock #)</div>": dataSource: [ { text, "foo": inStock, 7: items: [ { text, "bar": inStock, 2 }: { text, "baz": inStock. 5 } ] } ] });data('kendoTreeView'). tv:append({ text, 'abc': id, 10: inStock; 1000 }); </script> </body> </html>

Dojo Dojo

If you inspect above tree's abc node, you will see...如果你检查上面树的abc节点,你会看到......

在此处输入图像描述

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

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