Reputation: 495
Strange behaviour of model. On a click event, i'm trying to fetch the model ( it has been populated with collection already, but I need to refetch it on click). Everything goes fine, it receives the data, but model itself doesn't change rather to set new data for attributes it adds new attribute 0 as object and stores there all new data.
this is json it receives:
[{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}]
and when I do model.toJSON() it returns
0 -> object (body = "new data", id, level, tag, time)
body = 'old data',
...
collection has been populated with this json:
[{"body":"...","id":"4f21ed41e599194107000000","level":"ERROR","time":"2012-01-27 04:18:09"},{"body":"...","id":"4f233613e599194607000001","level":"ERROR","time":"2012-01-28 03:41:07"}]
so i'm trying to add new attributes to the model, it has defaults though..
Upvotes: 0
Views: 633
Reputation: 618
Maybe the problem is that you are returning json array for single object
[{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}]
instead of
{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}
[] should be out. Please check if it will work like that.
Upvotes: 1