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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745437141a4627659.html

相关推荐

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

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

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信