利用骨干localStorage的和仍在进行调用服务器 [英] Using Backbone LocalStorage and still making calls to the server
本文介绍了利用骨干localStorage的和仍在进行调用服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何向服务器的呼叫使用骨干的localStorage我看到了这个问题,但我不知道我在哪里申请呢?
How do I make a call to the server using Backbone localStorage I saw this question, but I am not sure where I apply it?
<一个href=\"http://stackoverflow.com/questions/5761349/backbone-js-able-to-do-rest-and-localstorage\">Backbone.js能够做到的休息和localStorage的?
下面是我的code的观点:
Here is my code for the view:
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不工作给我这个错误:
this.model.save does not work giving me this error:
Uncaught TypeError: Object function (){return r.apply(this,arguments)} has no method 'save'
我试图做一个Ajax后到我的服务器在该URL。
I am trying to make an ajax-post to my server at that url.
推荐答案
我有一个错误,因为你还没有实例化模型。相反
I've got an error because you haven't instantiate your model. Instead
model: SearchM,
你应该有
model: new SearchM(),
这篇关于利用骨干localStorage的和仍在进行调用服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文