この記事の例では、JSツリープラグインZtreeで選択したすべてのノードデータを取得する方法について説明します。参照のためにそれを共有してください。特定の分析は次のとおりです。
私は物事の木側に慣れていないからです。私は中国人によって書かれたZtreeをオンラインで見ました。したがって、APIは中国語でなければなりません。コメントも良いです。したがって、プロジェクトでZtreeを使用してみてください。これは、選択したすべてのノードデータを簡単に取得できます。理解するためにAPIを見てください。だから私はちょうどコードをアップロードしました。
次のようにコードをコピーします:<!doctype html>
<html>
<head>
<Title> Ztree Demo-標準データ</title>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<link rel = "styleSheet" href = "css/ztreestyle/ztreestyle.css" type = "text/css">
<link rel = "styleSheet" href = "css/demo.css" type = "text/css">
<script type = "text/javascript" src = "js/jquery-1.4.4.min.js"> </scrip>
<script type = "text/javascript" src = "js/jquery.ztree.core-3.4.js"> </script>
<script type = "text/javascript" src = "js/jquery.ztree.excheck-3.4.js"> </script>
<! -
<script type = "text/javascript" src = "js/jquery.ztree.exedit-3.4.js"> </script> - >
<script type = "text/javascript">
<! -
var setting = {
チェック:{
有効:true
}、
/*データ: {
SimpleData:{
有効:true
}
}*/
データ: {
SimpleData:{
有効:true
}
}、
折り返し電話:{
ONCHECK:ONCHECK
}
};
var znodes = [
{id:1、pid:0、name: "will at will atをチェック"、open:false}、
{id:11、pid:1、name: "1-1 at will at"、open:true}、
{id:111、pid:11、name: "check 1-1-1"}、
{id:112、pid:11、name: "1-1-2でウィルでチェック}}、
{id:12、pid:1、name: "1-2 at will"、open:true}、
{id:121、pid:12、name: "1-2-1 at well"}、
{id:122、pid:12、name: "1-2-2を自由にチェックしてください"}、
{id:2、pid:0、name: "will at will"、open:false}、
{id:21、pid:2、name: "2-1 at well"}}、
{id:22、pid:2、name: "2-2 at will"、open:true}、
{id:221、pid:22、name: "2-2-1 at well"}、
{id:222、pid:22、name: "Check 2-2-2"}、
{id:23、pid:2、name: "2-13を自由にチェックしてください"}
];
$(document).ready(function(){
$ .fn.ztree.init($( "#treedemo")、setting、znodes);
});
function oncheck(e、treeid、treenode){
var treeobj = $。fn.ztree.getztreeobj( "treedemo")、
nodes = treeobj.getCheckedNodes(true)、
v = "";
for(var i = 0; i <nodes.length; i ++){
v + = nodes [i] .name + "、";
アラート(nodes [i] .id); //選択したノードの値を取得します
}
}
//->
</script>
</head>
<body>
<div>
<ul id = "treedemo"> </ul>
</div>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。