A "url" 属性 or function must be specified backbone.js save

A "url" property or function must be specified backbone.js save

我想执行函数中看到的更新操作。但是在更新时,city.save () 函数 returns 显示屏幕图像和 header 中的错误。为什么会这样?你能帮帮我吗

define(['text!components/wseducationconfirm/wseducationConfirmTemplate.html'], function (template) {
        var cityTemplate = Handlebars.compile(template);

var CityModel = Backbone.Model.extend({});

var CityCollection = Backbone.Collection.extend({
    url: "/api/epermit",
    model: CityModel
});
return Backbone.View.extend({

    el: "#content",
    initialize: function () {
        this.cities = new CityCollection();
        this.listenTo(this.cities, "reset add change remove", this.render);
        this.cities.fetch({reset: true});

    },
    events: {
        'click .confirmEntryPermit':'confirmEntryPermit'
    },
    confirmEntryPermit: function (e) {
        var value = 1;
        var id = $(e.currentTarget).data("id");
        var city = this.cities.findWhere({epermitId: id});
        city.set({wsEducation:value});
        city.save();
    },
    render: function () {
        for(var i = 0;i<this.cities.length;i++){

            var exdate =   new Date(this.cities.models[i].get("exitDate")).toISOString();
            exdate = exdate.substr(0,10);
            var endate = new Date(this.cities.models[i].get("entryDate")).toISOString();
            endate = endate.substr(0,10);

            if(this.cities.models[i].get("wsEducation") == 1){
                this.cities.remove(this.cities.models[i]);
            }else{
                this.cities.models[i].set({exitDate:exdate});
                this.cities.models[i].set({entryDate:endate});
            }
        }
        this.$el.html(cityTemplate({cities: this.cities.toJSON()}));
    }
  });
});

模型需要 id 属性才能从集合的 url 中派生出 url。您可以通过在模型选项

中设置 {idAttirubute : 'epermitId'} 来解决此问题