2011-12-16 19 views
3

構文エラーが誰でも見ることができますか? jsTreeはレンダリングしません。jsTreeがレンダリングされない

プラスjQueryの1.7で奇妙なエラー:

"children": ["login", 
    { 
     "data": "results", 
     "state": "closed", 
     "attr": { 
      "id": "node-123" 
     } 
    } 
] 

上記"login"が誤っなります

Uncaught Error: Syntax error, unrecognized expression: #

var data = [ 
    { 
    "data": "Basics", 
    "state": "closed", 
    // omit `attr` if not needed; the `attr` object gets passed to the jQuery `attr` function 
    "attr": { "id": "1234", "some-other-attribute": "attribute_value" }, 
    "children": [{ 
     "data": "login", 
     "state": "closed", 
     "children": [ 
     { 
      "data": "results", 
      "state": "closed", 
      "attr": { "id": "node-123" } 
     }] 
    }] 
}]; 

$(function() { 
    $("#jstree").jstree({ 
     "json_data": { 

      //initial - demo only, usually takes json from the controller 
      //static data, or function(node, mappingBeforeRequestToserver) 
      "data": data, 


      //If both data and ajax are set the initial tree is rendered from the data string. 
      //When opening a closed node (that has no loaded children) an AJAX request is made. 
      "ajax": { 

       //data: mappingBeforeRequestToserver-function(node about to be open or -1). `this` will be the tree instance) 
       //url: function(node about to be open as a paramater or -1) retuns the ajax URL (like /get_children/node_2). 
       //The error and success functions- modifiying the results from the server before populating the tree 



       type: "POST", 
       async: true, 
       "url": "/echo/json/", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       cache: false, 
       success: function (msg) { 
        return msg; 
       }, 
       error: function() { 
        // TODO process error 
       } 
      }, 
//   "xsl": "flat", 
//   "override_ui": "true", 
//   "real_checkboxes": "true", 
      "plugins": ["themes", "json_data", "ui"] 
     } 
     // 1) if using the UI plugin bind to select_node 
    }).bind("select_node.jstree", function (event, data) { 
      // `data.rslt.obj` is the jquery extended node that was clicked 
      alert(data.rslt.obj.attr("id")); 
     }) 
}); 
+0

エラーメッセージが参考になります。 –

+0

申し訳ありません。私は自分のq –

答えて

3

はそれを見つけた:余分な}

後の "プラグイン":[ "テーマ"、 "json_data"、 "UI"]

0

問題になる可能性があるようにこれが見えます。 jsTree documentationは、"children"属性が "子ノードの配列オブジェクト"である必要があると言います。 "login"Stringの存在がこれに違反します。

+0

を削除しようとしましたが(私の更新されたqを参照してください)、それは助けになりませんでした –

+0

[jsFiddle](http://jsfiddle.net/)を設定することは可能ですか? – jabclab

+0

jsTree.jsをjsfiddleにアップロードする際に問題があります。オンラインでURLを見つけることができませんでした –

関連する問題