如何使用Backbone localStorage拨打服务器我看到了这个问题,但我不知道我在哪里申请它?
Backbone.js able to do rest and 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'
我正在尝试在该网址上向我的服务器发布ajax-post。
答案 0 :(得分:0)
我有一个错误,因为你没有实例化你的模型。代替
model: SearchM,
你应该
model: new SearchM(),