Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 主干-未为模型定义model.destroy()函数_Javascript_Json_Backbone.js - Fatal编程技术网

Javascript 主干-未为模型定义model.destroy()函数

Javascript 主干-未为模型定义model.destroy()函数,javascript,json,backbone.js,Javascript,Json,Backbone.js,出于某种原因,我在JavaScript中遇到一个类型错误,它与我试图调用“model.destroy()”的假定主干模型对象有关: 这是我的主干代码: var Team = Backbone.Model.extend({ idAttribute: "_id", urlRoot: '/api/teams' }); var TeamCollection = Backbone.Collection.extend({ model: Team }); var teamColle

出于某种原因,我在JavaScript中遇到一个类型错误,它与我试图调用“model.destroy()”的假定主干模型对象有关:

这是我的主干代码:

var Team = Backbone.Model.extend({
    idAttribute: "_id",
    urlRoot: '/api/teams'
});

var TeamCollection = Backbone.Collection.extend({
    model: Team
});

var teamCollection = new TeamCollection([]);
teamCollection.url = '/api/teams';
teamCollection.fetch(
    {
        success: function () {

            console.log('teamCollection length:', teamCollection.length);

        }
    }
);
var UserHomeMainTableView = Backbone.View.extend({
    tagName: "div",
    collection: teamCollection,
    events: {},
    initialize: function () {

        this.collection.on("reset", this.render, this);

    },
    render: function () {

        var teams = {
            teams:teamCollection.toJSON()
        };

        var template = Handlebars.compile( $("#user-home-main-table-template").html());

        this.$el.html(template(teams));

        return this;
    },
    addTeam: function (teamData) {
        console.log('adding team:', team_id);
    },
    deleteTeam: function (team_id) {

        console.log('deleting team:', team_id);
        var team = teamCollection.where({_id: team_id}); //team IS defined here but I can't confirm the type even when logging "typeof"
        console.log('team to delete', typeof team[0]);
        console.log('another team to delete?',typeof team[1]);
        team.destroy({      //THIS FUNCTION CALL IS THROWING A TYPEERROR
            contentType : 'application/json',
            success: function(model, response, options) {
                this.collection.reset();
            },
            error: function(model, response, options) {
                this.collection.reset();
            }
        });
    }
});
因此,我从node.js服务器获取数据,服务器返回JSON。JSON有cid和所有jazz,所以这些对象在某个时候曾经是主干模型

我只是不知道为什么这种类型的团队不是骨干模式


有什么想法吗?

。其中
返回一个数组。你需要改用

或者为结果数组中的每个模型调用destroy

.where({...}).forEach(function(model){
    model.destroy();
});