小白求问用ztree里的async里的url请求后得到的json数据如何赋值给一个变量,没有财富值了,求大神帮帮忙 10
1个回答
展开全部
<script type="text/javascript">
setSPRSelectData();
//ajax请求数据
function setSPRSelectData() {
//树代码
zNodes = [];
$.ajax({
url: "@Url.Content("~/Official/GetApprover")",
cache: false,
async: true,
success: function (result) {
var firstResult = $.grep(result.data, function (n, i) {
return n.SZJG == 0;
});
var secondResult = $.grep(result.data, function (n, i) {
return n.SZJG > 0;
});
$.each(firstResult, function (index, firstValue) {
if (firstValue.SZJG == 0) {
var firstNode = { id: firstValue.KeyId, pId: 0, name: firstValue.XM, open: false, nocheck: true, isParent: true };
zNodes.push(firstNode);
$.each(secondResult, function (index, secondValue) {
if (secondValue.SZJG == firstValue.RYBS) {
var secondNode = { id: secondValue.RYBS, pId: firstValue.KeyId, name: secondValue.XM, isParent: false };
zNodes.push(secondNode);
}
});
}
});
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}
});
}
</script>
setSPRSelectData();
//ajax请求数据
function setSPRSelectData() {
//树代码
zNodes = [];
$.ajax({
url: "@Url.Content("~/Official/GetApprover")",
cache: false,
async: true,
success: function (result) {
var firstResult = $.grep(result.data, function (n, i) {
return n.SZJG == 0;
});
var secondResult = $.grep(result.data, function (n, i) {
return n.SZJG > 0;
});
$.each(firstResult, function (index, firstValue) {
if (firstValue.SZJG == 0) {
var firstNode = { id: firstValue.KeyId, pId: 0, name: firstValue.XM, open: false, nocheck: true, isParent: true };
zNodes.push(firstNode);
$.each(secondResult, function (index, secondValue) {
if (secondValue.SZJG == firstValue.RYBS) {
var secondNode = { id: secondValue.RYBS, pId: firstValue.KeyId, name: secondValue.XM, isParent: false };
zNodes.push(secondNode);
}
});
}
});
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}
});
}
</script>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询