因为每个元素都有以下结构
playerID:301 playerName:“管理” playerNameFilterRowId:“管理” playerType:“ball” playerTypeOrder:1 ballID:28 ballName:“管理员” ballNameFilterRowId:“管理员” permissionLevelTypeID:1 权限:null proto :对象
在这个我应该删除这个元素,这是第118个元素sportsScores [118] .playerName
如果(sportsScores [i] .playerName ===“跳转数据(此处)”){
let sportsScores = values.data;
for (let i = 0; i < sportsScores.length; i++) {
//console.log(sportsScores[i].ballName + "<---sportsScores[i].ballName--->" + sportsScores[i].playerName);
if(sportsScores[i].playerName === "jump Data (here)") {
console.log("sportsScores[i].playerName.splice(i, 1);--->");
//sportsScores[i].playerName.splice(i, 1);
//sportsScores.splice(sportsScores[i].playerName,1)
//sportsScores.splice(sportsScores[i].playerName);
sportsScores.splice(sportsScores[118]);
//console.log("sportsScores.splice(sportsScores[118]);--->" , sportsScores.splice(sportsScores[118]));
//console.log("sportsScores[i].playerName.splice(i, 1);--->" , sportsScores.splice(sportsScores[i].playerName,1));
//console.log("sportsScores[i].playerName.splice(i, 1);--->" , sportsScores.splice(sportsScores[i].playerName));
//console.log("sportsScores[i].playerName.delete(i, 1);--->" , sportsScores.delete(sportsScores[i].playerName,1));
}
sportsScores[i]["ballNameFilterRowId"] = sportsScores[i].ballName;
sportsScores[i]["playerNameFilterRowId"] = sportsScores[i].playerName;
sportsScores[i]["playerTypeFilterRowId"] = sportsScores[i].playerType;
}
this.gridkendo.reloadDataSource(values.data);
**JSON structure**
(312) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
[0 … 99]
[100 … 199]
[200 … 299]
[300 … 311]
0
:
{playerID: 301, playerName: "Administration", playerType: "ball", playerTypeOrder: 1, ballID: 28, …}
1
:
{playerID: 302, playerName: "Special Events", playerType: "Node", playerTypeOrder: 2, ballID: 28, …}
2
:
{playerID: 304, playerName: "Off the Clock Settings", playerType: "Node", playerTypeOrder: 2, ballID: 28, …}
0:
playerID : 301
playerName : "Administration"
playerNameFilterRowId : "Administration"
playerType : "ball"
playerTypeOrder : 1
ballID : 28
ballName : "Admin"
ballNameFilterRowId : "Admin"
permissionLevelTypeID : 1
permissions : null
__proto__ : Object
答案 0 :(得分:0)
你的方式不同,删除元素的最好方法是找到索引,然后将其拼接为1。 试试这个
Var index = sportsScores.indexOf(function(obj){ return obj.playerName ==&#34;你的条件&#34;});
通过这个你可以获得索引来删除项目,而不需要循环。
要删除项目,只需拼接即可。
sportsScore.splice(指数,1);
此处的最后一个参数1不是要从索引中删除的元素。