the syntax you're trying doesn't work because the parameters sent into the set method are an object literal. the values on the left side of the : are treated as literal names, while the values on the right can be executed / interpreted code.
there's a few things you can do, though:
get, update, and set the entire array:
var a = myModel.get("myArray");
a[0] = 5
myModel.set("myArray", a);
myModel.get("myArray"); //=> [5, 1, 2]
the advantage in doing it this way is that you get the standard "change" events fired from the model because you are setting the value of the attribute on the model.
another way to do it would be to shortcut the process by using a get, and updating the array directly:
myModel.get("myArray")[0] = 5
myModel.trigger("change");
myModel.trigger("change:myArray");
myModel.get("myArray"); //=> [5, 1, 2]
the disadvantage here is that this won't fire the "change" events because you're not calling the set method. so, if you need those events, you have to fire them yourself, as i've shown.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…