检查这个小提琴并取消注释处理程序,一次一个。正确的方法是迭代元素的数组。检查评论以获取更多信息。
<ul id="tree6">
<li><input type="checkbox" checked><label>Root</label>
<ul>
<li class="bluetabs"><input type="checkbox"><label>Node 1</label>
<ul>
<li><input type="checkbox"><label>Node 1.1</label></li>
</ul>
</li>
<li><input type="checkbox" checked><label>Node 2</label>
<ul>
<li><input type="checkbox"><label>Node 2.1</label></li>
<li><input type="checkbox"><label>Node 2.2</label></li>
<li class="bluetabs"><input type="checkbox"><label>Node 2.3</label>
<ul>
<li><input type="checkbox"><label>Node 2.3.1</label></li>
<li><input type="checkbox"><label>Node 2.3.2</label></li>
</ul>
</li>
<li><input type="checkbox"><label>Node 2.4</label></li>
<li><input type="checkbox"><label>Node 2.5</label></li>
<li><input type="checkbox"><label>Node 2.6</label></li>
</ul>
</li>
</ul>
</li>
</ul>
<button id="test">Press to expand</button>
$('#tree6').checkboxTree({
initializeChecked: 'expanded',
initializeUnchecked: 'collapsed'
});
//If all the bluetabs are collapsed this will work. If you expand one of the blue ones, then it won't work for the other.
$('#test').click(function() {
$('#tree6').checkboxTree( 'expand', $('.bluetabs') );
});
//This will work regardless
$('#test').click(function() {
$('.bluetabs').each(function() {
$('#tree6').checkboxTree( 'expand', $(this) );
});
});