2012-03-01 16 views
2

私は.Net Webサービスからデータを取得する 'jsTree'ツリービューを作成しようとしています。 aノードのhref属性を除いて、すべてが機能しています。私が何をしようと、それは常に '#'としてレンダリングされます。 ドキュメントからわかるように、データオブジェクトのすべての属性がaノードにコピーされます。jsTree - Jsonデータのhref属性の設定

以下は私の現在のjsonオブジェクトの例です。とにかくhref属性がノードにコピーされない理由を理解できますか?

[ { "attributes" : { "id" : "rootnode_2", 
     "rel" : "root2" 
     }, 
    "children" : [ { "attributes" : { "id" : "childnode_9", 
       "rel" : "folder" 
      }, 
      "children" : [ { "attributes" : { "id" : "childnode_23", 
        "rel" : "folder" 
        }, 
       "children" : null, 
       "data" : { "href" : "http://www.google.com", 
        "title" : "Test_Below_1" 
        }, 
       "state" : null 
       } ], 
      "data" : { "href" : "http://www.google.com", 
       "title" : "Test_1" 
      }, 
      "state" : null 
     }, 
     { "attributes" : { "id" : "childnode_10", 
       "rel" : "folder" 
      }, 
      "children" : [ { "attributes" : { "id" : "childnode_24", 
        "rel" : "folder" 
        }, 
       "children" : null, 
       "data" : { "href" : "http://www.google.com", 
        "title" : "Test_Below_2" 
        }, 
       "state" : null 
       } ], 
      "data" : { "href" : "http://www.google.com", 
       "title" : "Test_2" 
      }, 
      "state" : null 
     } 
     ], 
    "data" : { "href" : "http://www.google.com", 
     "title" : "Glatt" 
     }, 
    "state" : "closed" 
    } ] 

これは私がツリーを初期化する方法です。

$("#jstreejson").jstree({ 
     json_data : { 
      "data": treeObject 
     }, 
     themes: { 
      "theme": "apple", 
      "dots": true, 
      "icons": true, 
      "url": "/Scripts/themes/apple/style.css" 
     }, 
     plugins: ['core', 'themes', 'json', "json_data"] 
    }); 

答えて

2

だから私はそれがまったく正しいとは思わない。あなたは、アンカーが私の知る限りの属性がありますが、JSONでattrハッシュにコンテンツを追加しませんし、目的のリンク、すなわちを開くためにselect_node.jstreeイベントを使用することができるかを制御することはできません。

.bind("select_node.jstree", function (e,data) { 
    var href_address = data.rslt.obj.attr("whatever"); 
    // open desired link 
} 
+0

に試してみてくださいhrefの値を 'data'ハッシュではなく' attr'ハッシュに加えてください。 – Amir

+0

これは完全に機能しました。ありがとう! – Erik