吃完飯整理好
坐在電腦前 準備要開始晚上的工作
似乎聽到妹妹醒來的聲音
跑到床邊
妹妹看到了爸爸
微笑的張開雙手 抱住爸爸的臉
然後繼續睡著
晚安 妹妹
在sync被觸發時,sync會接收到3個參數Backbone.sync=function(method,model,options){}
Backbone.sync=function(method,model,success,error){
alert("method="+method+" model="+model.get("isLogin"));
};
model.save({isLogin:false})
model.save( {isLogin:false}, {error:function(model, response){..}, {success:function(model, response){} })
2.改寫model內sync的functionitem.set({url:"save.php"}) item.save()
window.Item=Backbone.Model.extend({ "sync":function(method, model, options){ switch(method){ case "read": options.url = "json_sample/playerInfo.json"; break; case "create": options.url = model.url + '/create'; break; case "update": options.url = 'mytest/update.php'; break; case "delete": options.url = model.url + '/delete'; break; } return Backbone.sync(method, model, options); } }); Backbone.sync=function(method,model,options){ alert("from sync method="+method+" model="+JSON.stringify(model)+" url="+options.url); };
{ "isLogin":true, "nowPlayList":"my", "nowPlayIndex":0 } client端 window.Item=Backbone.Model.extend() window.item=new Item({id:5}); item.url="json_sample/Info.json"; item.fetch(); item.bind("change:isLogin",function(){ console.log('chang isLogin') })
window.Item=Backbone.Model.extend({ url:function(){ return 'server/simple.json'; }, myname:'OZClass' }); window.item=new Item({}); item.fetch({ success:function(response,model){ } })
window.Item=Backbone.Model.extend({ parse:function(response){ response.name="["+response.name+"]"; console.log(response.name) return response }, });