backbone.js - Model fetch including model as attribute in backbone -


here test code:

var stat = backbone.model.extend({         defaults: {             power: 0,             speed: 1         }     });      var player = backbone.model.extend({         defaults: {             name: "igor",             surname: "ola",             stats: null          },          urlroot: "/cgi-bin/test.pl"     });      var player = null;       $(document).ready(function(){         player = new player();         player.set("stats", new stat());         player.fetch({             success: function() {                 var text = player.get("stats").get("power");                 console.log(text);             }         });     }); 

what expect backbone update player model , it's stats attribute, model (stat).

but doesn't work. there way it? goal update such model in 1 fetch.

the player.get("stats") returns object, not stat model instance.


Comments