<script src="~/Scripts/jstree.js"></script>
<script type="text/javascript">
$(function () {
LoadTree(function (result) {
$('#tree').jstree({
"core": {
"data": result,
"multiple": false,
"animation": 200,
"check_callback": true,
"themes": {
"icons": false,
"stripes": true,
"dots": true
}
},
"plugins": ["state", "types", "wholerow"] //"dnd", "contextmenu", "search",
});
});
});
function LoadTree(callback) {
$.ajax({
type: 'GET',
url: '/Edit/LoadTree',
dataType: 'text',
contentType: 'application/json',
cache: false,
success: function (data) {
callback(JSON.parse(data));
},
error: function (xhr, ajaxOptions, error) {
alert(xhr.status);
alert('Error: ' + xhr.responseText);
}
});
}
</script>
<script src="~/Scripts/jstree.js"></script>
<script type="text/javascript">
$(function () {
$('#tree').jstree({
"core": {
'data': {
type: 'GET',
url: function () { return '/Edit/LoadTree'; },
dataFilter: function (response) {
return JSON.parse(response);
}
},
"multiple": false,
"animation": 200,
"check_callback": true,
"themes": {
"icons": false,
"stripes": true,
"dots": true
}
},
"plugins": ["state", "types", "wholerow"] //"dnd", "contextmenu", "search",
});
});
}
"search": {
"ajax": {
url: "/Reports/SearchTree",
dataType: 'text',
contentType: 'application/json',
data: function () {
return this.data.search.str;
}
}
},
"search": {
"ajax": {
url: "/Reports/SearchTree",
dataType: 'text',
contentType: 'application/json',
data: function () {
return this.data.search.str;
},
cache: false,
dataFilter: function (response) {
console.log(JSON.parse(response));
return JSON.parse(response);
}
}
},
this._search_load = function (d, str) { var res = true, t = this, m = t._model.data; $.each(d.concat([]), function (i, v) { if(m[v]) { if(!m[v].state.loaded) { t.load_node(v, function () { t._search_load(d, str); }); res = false; } } }); if(res) { this.search(str, true); } };dataType: 'text',
to 'json' (not text), and lose the dataFilter - all you need to do is return a string from the server in the format: ["asfd","asdf2"]
Response.Headers.Add("Content-type", "text/json");
Response.Headers.Add("Content-type", "application/json");
Response.Write(JsonConvert.SerializeObject(all));
$('#treeReport').jstree({
"core": {
'data': function (node, cb) {
var vars = {
Action: 'Load'
}
$.ajax({
type: 'POST',
url: '/Edit/LoadTree',
dataType: 'text',
contentType: 'application/json',
data: JSON.stringify(vars),
cache: false
}).done(function(d) { cb(JSON.parse(d)); })
},
"multiple": false,
"animation": 200,
"check_callback": true,
"state": { "key": "tree" },
"themes": {
"icons": false,
"stripes": true,
"dots": true
}
},
"search": {
"ajax": {
url: "/Reports/SearchTree",
dataType: 'json',
contentType: 'application/json',
data: function () {
return this.data.search.str;
},
cache: false,
dataFilter: function (response) {
console.log(JSON.parse(response));
return JSON.parse(response);
}
}
},
"plugins": ["state", "types", "wholerow", "search"] //"dnd", "contextmenu",
});
var type = x.getResponseHeader('Content-Type');
if (s.dataType = 'json')
{
return callback.call(this, this._append_json_data(obj, d));
}
'data': function (node, cb) {
$.ajax(
type: 'GET',
dataType : 'json',
url: function () { return '/Edit/LoadTree'; }
}).done(function(d) { cb(JSON.parse(d)); })
},