最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Backbone.js: stage new model without saving - Stack Overflow

programmeradmin2浏览0评论

Is there a way in backbone.js to set up a new model (i.e. instantiate the class with empty attributes), without saving it back to the server?

Specifically, I have a collection which contains several items. When I want to create a new item within my collection, I call collection.create {}. This automatically saves the empty model back to my database.

In Rails, there's a difference between Class.create, which actually creates a database record, and Class.new, which simply creates one in memory and has to be manually saved. I'm basically looking for a backbone equivalent.

Is there a way in backbone.js to set up a new model (i.e. instantiate the class with empty attributes), without saving it back to the server?

Specifically, I have a collection which contains several items. When I want to create a new item within my collection, I call collection.create {}. This automatically saves the empty model back to my database.

In Rails, there's a difference between Class.create, which actually creates a database record, and Class.new, which simply creates one in memory and has to be manually saved. I'm basically looking for a backbone equivalent.

Share Improve this question edited Mar 20, 2012 at 13:35 noah 21.5k17 gold badges68 silver badges88 bronze badges asked Mar 10, 2012 at 16:13 Kevin WhitakerKevin Whitaker 13.5k13 gold badges54 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Instead of Collection.create, use Collection.add.

发布评论

评论列表(0)

  1. 暂无评论