如何修复未捕获的TypeError:无法读取属性' prototype'的未定义? [英] How to fix Uncaught TypeError: Cannot read property 'prototype' of undefined?
问题描述
我有一个小问题.我正在使用bone.js.我像示例中那样编写了这段代码:
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()
这将导致错误:Uncaught TypeError: Cannot read property 'prototype' of undefined
.但是存在数据以作为响应.图片中的详细信息.如何解决这个问题?
谢谢您的回答.
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.
这篇关于如何修复未捕获的TypeError:无法读取属性&#39; prototype&#39;的未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!