backbone.js - save model object using backbone -


i'm using backbone,and have model data like:

{   "a":[{"a1":"name1","a2":"add2"},{"a1":"name3","a2":"add3"}],"c":"data1" } 

now want edit , add data,i set data like:

        var clone = $.extend([], model.get("a"));         for(var i=0;i<count;i++){             clone[i].a1= "a"+i;             clone[i].a2= "b"+i;             clone[i].a3= "c"+i;         }         model.set({a:clone}); 

but says "clone[i]" undefined,while when there 1 object(count=1), can works,i don't know why. hope help,thanks.

what count? should work:

_.map(clone, function (item, index) {     item.a1 = "a" + index;     item.a2 = "b" + index;     item.a3 = "c" + index;     return item; }); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -