Backbone.js model.get() returning 'undefined' even though I can see the attributes in console.log

前端 未结 3 703
轻奢々
轻奢々 2020-11-29 10:32

I have a model instance, which I set another model instance on, i.e model.set(\'rsvp\', new App.Rsvp).

When I iterate over the collection to generate th

3条回答
  •  無奈伤痛
    2020-11-29 10:59

    model.rsvp = foo; (lets call this code bit #1) which is equivalently model['rsvp'] = foo; is not the same as model.set({'rsvp':foo}); (code bit #2). If you want to tack another model instance foo (or some other object or value) onto a model instance model, use the code bit #1 or its equivalent. If you want to add an attribute value pair to a model instance that might eventually be permanently stored somewhere, use the code bit #2. Likewise, you're only going to have model.rsvp defined if you used model.rsvp = foo; or model['rsvp'] = foo;

提交回复
热议问题