js中json的添加和指定位置的删除

0】绑定数据

grid = $("#Grid").datagrid({
fit: true,
rownumbers: true,
fitColumns: true,
height: $(window).height() * 0.8,
singleSelect: false,
columns: [[
{ field: "ck", checkbox: true },
{ field: "Name", title: "用户名", width: 50, sortable: true },

]],
url: "/Admin/UserInfo/测试",

});

1】先定义一个数组

var All_commentUserArr = new Array();

2】给数组添加数据

var crows = $('#Grid').datagrid("getSelections");
if (crows.length > 0) {
for (var i = 0; i < crows.length; i++) {
var o = new Object();
o.Id = crows[i].Id;
o.Name = crows[i].Name;
All_commentUserArr.push(o);//这一步是添加数据
}
}

3】删除数据(根据选择的)

var crows = $('#Grid').datagrid("getSelections");
//先删除数组中所有数据当前单位的数据
if (crows.length > 0) {
for (var i = 0; i < crows.length; i++) {
for (var j = 0; j < All_commentUserArr.length; j++) {
if (All_commentUserArr[j] == crows[i]) {
var index = All_commentUserArr.indexOf(crows[i]);
if (index > -1) {
All_commentUserArr.splice(index, 1);
}
break;
}
}
}
}
createSelectGrid(All_commentUserArr);

上一篇:Ant Design Upload 组件上传文件到云服务器 - 七牛云、腾讯云和阿里云的分别实现


下一篇:AWK文本处理工具(Linux)