javascript - Convert AJAX callback data to Backbone model -


is there way convert success callback data backbone model? these have:

app.models.image = backbone.model.extend({   idattribute : 'image_id' });  app.collections.image = backbone.collection.extend({   model : app.models.image,   url : json_url,   fetchimage : function(model) {     var self = this;     var imageid = model.id, name = model.get('name');      this.fetch({       data : {         packet : json.stringify({           type : 'loadimage',           param : {             image_id : imageid,             filename : name           }         })       },       type : 'post',       success : function(data) {             var `view` = new app.views.image({           model : data         });          view.render();       },       error : function() {       }     });   } }); 

looking @ success function, declared view callback data model. when program calls render function, model being displayed [object] (based on console.log) assume data passed object, , not backbone model.

note: app.collections.image dependent collection. works fine, , have nothing worry it.

you should pass instance of model view

 var `view` = new app.views.image({    model : new app.models.image(data)  }); 

note : not sure trying achieve fetching collection , using response initiate model.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -