我的代码可以在 Chrome 控制台中获取数据
但无法在我的程序中获取数据
像这样的代码:
$(document).ready(function () {
var theme = '';
var source = [];
var rsps = '';
$.ajax({
url: '@Url.Content("~/Home/RoleMenus")',
type: "GET",
cache: false,
success: function(response, status, xhr) {
rsps = response;
source = eval(response);
},
error: function(XMLHttpRequest,textStattus,errorThrown) {
$('#jqxErrorMsg').html(errorThrown);
}
});
for(var src in source) {
if (src.items.legth > 0) {
src.expanded = true;
}
}
// Create jqxTree
$('#jqxTree').jqxTree({ source: source, theme: theme});
$('#jqxTree').bind('select', function (event) {
var args = event.args;
var item = $('#jqxTree').jqxTree('getItem', args.element);
for (var menu in source[0]) {
if (item.label == menu.label) {
window.location = menu.actionUrl;
//break;
}
}
});
});
=====更新===== 如果我移动,响应是正确的
// Create jqxTree
$('#jqxTree').jqxTree({ source: source, theme: theme});
进入success: function(response, status, xhr) {}
菜单显示正确
但source
变量在外面仍然没有价值
=====解决了====
for (var menu in source[0])
应该
for (int i=0;i<source[0].length;i++)