1
我是Backbone.js和Require.js的新手我試圖從服務器獲取數據並將其存儲在我的骨幹模型中。問題是數據沒有填充模型。從服務器Json數據不填充骨幹模型
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())我得到 - 對象{id:「1Uw6ZkbsAH8」,video_id:「」,video_name:「」}。我究竟做錯了什麼?