jquery 实现Json节点的增删改查

话不多说,直接上代码
var obj = [{"name": "oyc", "number": "006"}, {"name": "yqr", "number": "007"}];
var person = {"name": "qq", "number": "001"};
function add(obj,person) {
    obj.push(person);
    console.log("Congratulations,add done!");
}
function del(obj,person) {
    $.each(obj, function (n, value) {
        if (value.name == person.name) {
            obj.splice(n, 1);//t.remove(0);
            console.log(person.name+" has deleted");
        }
    })
}
function edit(obj,person) {
    $.each(obj, function (n, value) {
        if (value.name == person.name) {
            obj[n].name="123";
            console.log(person.name+" has deleted");
        }
    })
}
function listObj(obj) {
    $.each(obj, function (n, value) {
        console.log(n + " - " + value.name,value.number);
    });
}

  

posted @ 2018-05-25 16:05  乾源  阅读(194)  评论(0编辑  收藏  举报