简体   繁体   English

我想用Jquery AciTree迭代选中的复选框

[英]I want to iterate the checked checkbox with Jquery AciTree

I want to iterate the checked checkbox with Jquery AciTree 我想用Jquery AciTree迭代选中的复选框

This dont work. 这不行。

    var api = $('#arbol_actividades').aciTree('api');
    var sel = api.checkboxes($('#arbol_actividades li'), true);
    sel.each(function(index,item){
        api.getId((item));
    });

Since item is a DOM element, it must be jQuery-wrapped before passing it to AciTree API functions. 由于item是一个DOM元素,因此在将其传递给AciTree API函数之前必须先进行jQuery包装。 Test: 测试:

1 . 1 Open this official demo page , for example, in Google Chrome. 打开此官方演示页面 ,例如,在Google Chrome中。

2. Open the console (F12 in case of Chrome). 2.打开控制台(如果是Chrome,则为F12)。

3. Check some checkboxes of the tree on the left. 3.检查左侧树的一些复选框。

4. Copy and paste this code into the console, and press Enter: 4.将此代码复制并粘贴到控制台中,然后按Enter键:

var api = $('#tree').aciTree('api'),
    leaves = $("#tree .aciTreeLi .aciTreeLeaf"),
    checked = api.checkboxes(leaves, true);

checked.each(function (index, item) {
    var $item = $(item);
    console.log(api.getId($item) + ": " + api.getLabel($item)); 
});

This should print the ID and the label of the selected leaf nodes. 这应该打印所选叶节点的ID和标签。 Example: 例:

树

Console output: 控制台输出:

3: Audi 
5: Buick
7: Chevrolet
8: Chrysler 

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

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