Backbone.js的未捕获类型错误:对象[对象数组]有“开”都没法 [英] Backbone.js Uncaught TypeError: Object [object Array] has no method 'on'

查看:111
本文介绍了Backbone.js的未捕获类型错误:对象[对象数组]有“开”都没法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我这个吗?我不知道发生了什么事情错了。

Can anyone help me with this one? I don't know what's going wrong.

从JSON文件获取数据:

Getting data from a json file:

this.categoryTrees = new CategoryTrees();
this.categoryTrees.getCategoryTreesFromJSON();

this.categories = new Categories();
this.categories.getCategoriesFromJSON();

为它创建视图:

//view for startscreen
this.startscreenView = new StartscreenView({collection: this.categoryTrees});

//view for subjectsList
this.subjectsListView = new SubjectsListView({collection: this.categories.where({ category_tree : "onderwerpen" }) });

与第二个where子句给我一个错误:未捕获类型错误:对象[对象数组]有'对'都没法

The second one with the where clause gives me an error: Uncaught TypeError: Object [object Array] has no method 'on'

当我不忍受它工作得很好where子句。在控制台我能够没有任何问题执行,其中的功能。

When I don't put up the where clause it works just fine. In console I am able to perform the where function without any problems.

我怀念这里的东西吗?

推荐答案

,其中方法将返回所有集合中匹配传入属性的模型的数组。因此,它不返回 Backbone.Collection 让您获得未定义的错误。

The where method will return an array of all the models in a collection that match the passed attributes. So it doesn't return a Backbone.Collection so you get the on undefined error.

您需要从结果创建一个新的类别集合其中,

You need to create a new Categories collection from the result of the where with :

this.subjectsListView = new SubjectsListView({
    collection: new Categories(
        this.categories.where({ category_tree : "onderwerpen" })) 
});

这篇关于Backbone.js的未捕获类型错误:对象[对象数组]有“开”都没法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆