在rails 4.2.2中,我正在尝试为jstree加载祖先数据,但它没有加载&它也没有显示任何错误。参考http://tech.sunilnkumar.com/2014/03/28/tree-hierarchy-with-js-tree-and-ancestry/
当我在javascript控制台中尝试以下脚本时,
$("#category-hierarchy").jstree({
"json_data": {
"ajax" : {
"url" : $("#category-hierarchy").attr('data-path'),
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
plugins : ["themes", "json_data", "ui"],
themes : {"theme": "default", "icons":false, "dots": true, "open":true},
core: {"animation": 100}
});
我得到了一个结果,
$.jstree.core {_id: 1, _cnt: 0, _wrk: null, _data: Object, _model: Object…}
_cnt: 0
_data: Object
_id: 1
_model: Object
_wrk: null
element: jQuery.fn.init[1]
settings: Object
__proto__: Object
Category.arrange_serializable
的祖先数据
[{"id"=>1, "ancestry"=>nil, "user_id"=>1, "asset_id"=>nil, "root_node"=>true, "created_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "updated_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "children"=>[{"id"=>2, "ancestry"=>"1", "user_id"=>1, "asset_id"=>1, "root_node"=>false, "created_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "updated_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "children"=>[]}, {"id"=>3, "ancestry"=>"1", "user_id"=>1, "asset_id"=>2, "root_node"=>false, "created_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "updated_at"=>Mon, 14 Sep 2015 04:53:25 UTC +00:00, "children"=>[]}]}]
如何为祖先数据生成jstree?