如何使用 Backbone localStorage 调用服务器我看到了这个问题,但我不确定我在哪里应用它?
Backbone.js 能够做 rest 和 localstorage 吗?
这是我的视图代码:
define([
'jquery',
'underscore',
'backbone',
'models/song',
//'collections/songs',
//'views/song',
'text!templates/search.html'
], function($, _, Backbone, SearchM, SearchT){ //Song, Songs, SongV,
var Search = Backbone.View.extend({
model: SearchM,
el: $("#Sirius"),
events: {
'submit #searchMusic': 'search'
},
search: function (search) {
console.log(SearchM);
this.model.save({
channel: this.$el.find('#channel'),
week: this.$el.find('#week'),
year: this.$el.find('#year'),
filter: this.$el.find('#filter')
});
console.log('saved');
},
render: function () {
this.$el.html( SearchT );
}
});
return Search;
});
这是模型:
define([
'underscore',
'backbone'
], function(_, Backbone) {
var Search = Backbone.Model.extend({
url: '/music'
});
return Search;
});
this.model.save 不起作用给我这个错误:
Uncaught TypeError: Object function (){return r.apply(this,arguments)} has no method 'save'
我正在尝试在该 url 上向我的服务器发送 ajax-post。