模型的奇怪行为。在点击事件中,我试图获取模型(它已经填充了集合,但我需要在点击时重新获取它)。一切顺利,它接收数据,但模型本身并没有改变,而是为属性设置新数据,它将新属性0作为对象添加,并存储所有新数据。
这是json收到的:
[{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}]
当我做model.toJSON()时,它返回
0 -> object (body = "new data", id, level, tag, time)
body = 'old data',
...
收集已用这个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"}]
所以我试图向模型添加新属性,但它有默认值..
答案 0 :(得分:1)
也许问题是你要为单个对象返回json数组
[{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}]
而不是
{"body":"..","id":"4f24e353e599194e07000003","level":"ERROR","tag":"DED00","time":"2012-01-29 10:12:35","trace":"..."}
[]应该出来了。请检查它是否会像那样工作。