如何解决未捕获类型错误:无法读取的未定义的属性“原型”? [英] How to fix Uncaught TypeError: Cannot read property 'prototype' of undefined?
问题描述
我有一个小问题。我使用Backbone.js的。我写这篇code像例如:
I have a little problem. I'm using backbone.js. I wrote this code like in example:
<script>
$(document).ready(function () {
window.App = {
Views: {},
Models: {},
Collections: {}
}
App.Collections.Users = Backbone.Collection.extend({
model: App.Models.User,
url: 'service'
});
App.Models.User = Backbone.Model.extend({});
App.Views.App = Backbone.View.extend({
initialize: function() {
console.log( this.collection.toJSON() );
}
});
});
</script>
比我开始服务器,并在浏览器控制台输入:
Than I started server and in browser console type this:
var x =new App.Collections.Users();
x.fetch()
和这个如下错误:未捕获类型错误:无法读取属性未定义的原型
。但数据是响应present。细节图片。如何解决这一问题?
感谢您的答案。
And this follows to error: Uncaught TypeError: Cannot read property 'prototype' of undefined
. But data is present in response. Details in picture. How to fix this?
Thanks for you answers.
推荐答案
我修正了这个错误。问题是,我创建的集合,然后模型。集合使用用户模型,工作单位,但是当我定义这个集合,我没有定义模型。
I fixed this bug. The problem was that I created Collection and then the Model. Collections use user model, as working unit, but when I defined this Collection, I did not define Model.
所以,如果你想避免这个错误,首先定义一个模型,然后才定义集合。
So, if you want to avoid this bug, firstly define a Model and only then define the Collection.
这篇关于如何解决未捕获类型错误:无法读取的未定义的属性“原型”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!