How do I fetch a single model in Backbone?

前端 未结 7 1123
误落风尘
误落风尘 2020-11-30 18:36

I have a Clock model in Backbone:

var Clock = Backbone.Model.extend({});

I\'m trying to get an instance of that that has the l

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 19:14

    You probably should be accessing the object trough a collection and keeping it in the collection all the time. This is how to do it:

    var AllClocks = Backbone.Collection.extend({
      model: Clock,
      url: '/clocks/'
    });
    
    var allClocks = new AllClocks();
    my_clock = allClocks.add({id: 123});
    my_clock.fetch()
    

提交回复
热议问题