使用 Backbone LocalStorage 并仍调用服务器

Using Backbone LocalStorage and still making calls to the server

本文关键字:调用 服务器 Backbone LocalStorage 使用      更新时间:2023-09-26

如何使用 Backbone localStorage 调用服务器 我看到了这个问题,但我不确定在哪里应用它?

骨干网.js能够进行休息和本地存储?

这是我的视图代码:

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。

我有一个错误,因为你还没有实例化你的模型。相反

 model: SearchM,

你应该有

 model: new SearchM(),