这是我的json数据。我正在使用这个json来创建树视图,现在我不确定如何在这个数据中添加Onclick事件,当我选中或取消选中一个复选框时,它会调用我可以跟踪chekbox的对应id的函数。
[{
"id":1,
"text":"Forest",
"children":[{
"id":22,
"text":"Animal",
"state":"closed",
"children":[{
"id":31,
"text":"Lion",
"checked":true
},{
"id" : 14,
"text":"Tiger"
}]
}]
}]
HTML部分看起来像这样:
<ul checkbox="true" url="tree_data.json" class="easyui-tree tree" id="tt">
<li>
<div class="tree-node" id="_easyui_tree_1">
<span class="tree-hit tree-expanded"></span>
<span class="tree-icon tree-folder tree-folder-open"></span>
<span onclick="check(this.id)" class="tree-checkbox tree-checkbox2"></span>
<span class="tree-title">Forest</span>
</div>
<ul style="display: block;">
<li><div class="tree-node" id="_easyui_tree_2">
<span class="tree-indent"></span>
<span class="tree-hit tree-expanded"></span>
<span class="tree-icon tree-folder tree-folder-open"></span>
<span onclick="check(this.id)" class="tree-checkbox tree-checkbox2"></span>
<span class="tree-title">Animal</span>
</div>
<ul style="display: block;">
<li><div class="tree-node" id="_easyui_tree_3">
<span class="tree-indent"></span>
<span class="tree-indent"></span>
<span class="tree-indent"></span>
<span class="tree-icon tree-file "></span>
<span onclick="check(this.id)" class="tree-checkbox tree-checkbox1"></span>
<span class="tree-title">Lion</span>
</div>
</li>
<li>
<div class="tree-node" id="_easyui_tree_4">
<span class="tree-indent"></span>
<span class="tree-indent"></span>
<span class="tree-indent"></span>
<span class="tree-icon tree-file "></span>
<span onclick="check(this.id)" class="tree-checkbox tree-checkbox0"></span>
<span class="tree-title">Tiger</span>
</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>