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); }); }
--------------少年不努力,长大搞程序。欢迎关注,如有错误,恳请指正。