我有一个json对象作为响应,使用我必须创建一个jstree。但是无法在javascript函数中读取json对象。
我的JavaScript:
var repoId = $('#frmHdnV').val();
// variable to hold request
var request= $.post("CreatJqueryTree",{repoId:repoId},function(data){},"json");
request.done(function (response, textStatus, jqXHR){
alert(response);
var tem = JSON.parse(response);
var obj = tem.data;
$("#tes").jstree({
"json_data" : {
"data" : // here i need that json object to create this tree
},
"plugins" : [ "themes", "json_data", "checkbox", "ui" ]
}).bind("select_node.jstree", function (e, data) { alert(data.rslt.obj.data("id")); });
});
request.fail(function (jqXHR, textStatus, errorThrown){
alert("....Not Done...");
alert(errorThrown);
});
响应我可以在firefox usinhg firebug中看到。但是如何从响应中读取json对象。
答案 0 :(得分:1)
试试这个:
$.post("CreatJqueryTree",{repoId:repoId},function(data){
$("#tes").jstree({
"json_data" : {
"data" : data
},
"plugins" : [ "themes", "json_data", "checkbox", "ui" ]
}).bind("select_node.jstree", function (e, data) { alert(data.rslt.obj.data("id")); });
},"json");