我是 Backbone.js 和 Require.js 的新手,我正在尝试从服务器获取数据并将其存储在我的骨干模型中。问题是数据没有填充模型。
require.config({
paths:{
jquery:"libs/jquery-1.7.1.min",
underscore:"libs/underscore-min",
backbone:"libs/backbone-min",
models:"models",
views:"views",
collections:"collections"
},
shim:{
"backbone":{
"deps":["underscore","jquery"],
"exports":"Backbone"
},
"underscore":{
"exports":"_"
}
}
});
require (['routes'],function() {
new Router ();
});
该模型
define (['jquery','underscore','backbone'],function($,_,Backbone){
Video = Backbone.Model.extend ({
defaults:{
video_id:'',
video_name:'',
},
urlRoot:"/video",
});
});//end define
路由器
define(['backbone','models/Video'],function(Backbone){
Router = Backbone.Router.extend({
routes:{
"/":"index",
},
initialize:function (){
this.index ();
},
index:function ()
{
video = new Video ({id:"1Uw6ZkbsAH8"});
video.fetch();
console.log (video.toJSON());
}
});
});//end define
我检查网络响应,我得到“{video_id:1,video_name:test_backbone}”作为响应,但是当我 console.log (video.toJSON()) 我得到 - Object {id: "1Uw6ZkbsAH8", video_id: " ",视频名称:""}。我究竟做错了什么?