【发布时间】:2018-11-14 07:15:30
【问题描述】:
我有一个包含以下数据的 JSON 数组
source=[{"OperationName":"All","PrivilegeName":"Roles CRUD"},
{"OperationName":"Read","PrivilegeName":"Roles Read Delete"},
{"OperationName":"Delete","PrivilegeName":"Roles Read Delete"},
{"OperationName":"Read","PrivilegeName":"Roles Update"},
{"OperationName":"Update","PrivilegeName":"Roles Update"}]
我有一个目标数组,即destination =[];
我创建了一个函数 bindRowEvent(),它从表中返回选定的行并将其保存到变量 _currentSelectedRow。
我正在尝试选择特定行并仅将所选值发送到目标数组。 我可以为第一个值执行此操作,但是在第二次调用该函数时,它只会覆盖目标中的第一个值
function AssignOne(_currentSelectedRow) {
debugger;
//destination.push(_currentSelectedRow);
if (destination.length == 0) {
destination = source.slice(_currentSelectedRow, 1);
}
else {
destination = source.slice(_currentSelectedRow, destination.length+1);
}
source.splice(_currentSelectedRow, 1);
console.log(destination);
displaySource();
displayDestination2();
bindRowEvent();
}
我该如何解决这个问题?
【问题讨论】:
-
destination.push() 不起作用?
-
你能从你的代码中创建一个小提琴吗?
标签: javascript jquery arrays json ajax