我一直在尋找Todo list example(source)Backbone.js。代碼使用本地存儲,我想嘗試轉換它,以便通過RESTful Web服務進行操作。從localStorage轉換主幹的待辦事項列表示例
假設webservice已存在於路由todos/
。我想我需要在url
中加入Backbone.Model.extend
,並在執行Backbone.collection.extend
時刪除localStorage: new Store("todos")
。
window.Todo = Backbone.Model.extend({
url : function() {
return 'todos/'+this.id;
}
// Default attributes for a todo item.
defaults: function() {
return {
done: false,
order: Todos.nextOrder()
};
},
// Toggle the `done` state of this todo item.
toggle: function() {
this.save({done: !this.get("done")});
}
});
這樣做的正確方法是什麼?
謝謝。我嘗試了這兩個改變,todos.js仍然沒有從服務中獲取待辦事項。我是否正確設置網址?任何機會,你可以張貼工作todos.js的代碼?看看http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example,我是否也需要擴展控制器? –
什麼請求被髮送到後端? –