this.collection.reset引发错误-未捕获类型错误:无法读取属性'原型'的未定义
this.collection.reset throwing error - Uncaught TypeError: Cannot read property 'prototype' of undefined
我试图重置集合,但当我这样做时,我会得到以下错误,
未捕获的类型错误:无法读取未定义的属性"prototype">
触发此重置的代码如下,
// Main object for the entire app
窗口。APP={
config: {
api: {
base:'http://app.local/api/v1/',
}
},
// Create this closure to contain the cached modules
module: function() {
// Internal module cache.
var modules = {};
// Create a new module reference scaffold or load an
// existing module.
return function(name) {
// If this module has already been created, return it.
if(modules[name]) {
return modules[name];
}
// Create a module and save it under this name
modules[name] = { Views: {} };
return modules[name];
};
}(),
init: function() {
// :: app start :: //
var app = POPS;
var Module = app.module( $( '#popsapp' ).data('route') );
// Creates a Master object in the global namespace so data can be passed in from the DOM.
// This would be replaced with a master Router if we weren't using actual pages
app.Initialiser = function( initialCollection ) {
this.start = function() {
//don't cache ajax calls
$.ajaxSetup({ cache: false });
console.log(Module);
if(Module.Collection !== undefined) {
this.collection = new Module.Collection();
this.view = new Module.Views.Master({ collection: this.collection });
} else {
this.view = new Module.Views.Master();
}
if(this.collection !== undefined) {
console.log(this.collection);
console.log(initialCollection);
console.log(this.collection.reset( initialCollection ));
this.collection.reset( initialCollection );
}
//moved this here so script runs after the DOM has loaded.
//but script.js still needs completely removing.
};
};
}
};
//应用程序的入口点APP.int((;
如果我在此之前记录this.collection
,则会在this.collection.reset( initialCollection)
处触发错误。我试图从中创建集合的JSON如下,
[
{
"name": "Organisation 1",
"information": "This is some information about the organisation!",
"notifications": "0",
"add_all": "0",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "organisation",
"clients": [
{
"id": "1",
"name": "Client 1",
"information": "A client called Client 1",
"add_all": "0",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "client",
"pivot": {
"organisation_id": "1",
"client_id": "1"
}
},
{
"id": "2",
"name": "Client 2",
"information": "A client called Client 2",
"add_all": "1",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "client",
"pivot": {
"organisation_id": "1",
"client_id": "2"
}
}
],
"projects": [
{
"id": "1",
"name": "Project #1",
"description": "Descriptive text.",
"total_cost": "0.00",
"start_date": "2014-01-01",
"finish_date": "2014-12-31",
"run_number_days": "365",
"num_days_from_year_start": "0",
"color": "#92e807",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"user_id": "1",
"pivot": {
"organisation_id": "1",
"project_id": "1"
}
}
],
"members": [],
"teams": []
},
{
"name": "Organisation 2",
"information": "This is some information about Organisation 2",
"notifications": "0",
"add_all": "0",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "organisation",
"clients": [],
"projects": [],
"members": [],
"teams": []
},
{
"name": "Client 1",
"information": "A client called Client 1",
"add_all": "0",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "client",
"members": [
{
"id": "1",
"email": "user@domain.com",
"first_name": "User",
"last_name": "Name",
"display_name": "",
"initials": null,
"remember_me": null,
"login_type": "normal",
"api_token": null,
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"deleted_at": null,
"pivot": {
"client_id": "1",
"user_id": "1"
}
}
]
},
{
"name": "Client 2",
"information": "A client called Client 2",
"add_all": "1",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"type": "client",
"members": []
}
]
json是完全有效的,我不确定问题出在哪里。有人有什么想法吗,它读起来像是this.collection
没有定义,这就是为什么我不能在它上运行reset((,但当我记录它时,我可以看到collciton。
collection.reset()
方法将骨干模型的数组作为输入。您的数组(initialCollection
(只是一个通用的JavaScript数组。
相关文章:
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 未捕获的类型错误:无法读取属性'name'即使它存在,也无法定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- 未捕获的类型错误:无法读取属性'中止'的未定义
- Javascript未捕获类型错误:无法读取属性'0'的未定义
- jQuery控制台错误:无法读取属性'top'的未定义
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- 我该如何解决这个问题?“未捕获的类型错误:无法读取 null 的属性'appendChild'”
- json-api和错误结果:无法读取属性'长度'的未定义
- VM5111:1249未捕获类型错误:无法读取属性'x'为null
- 未捕获的类型错误:无法读取属性'道具'reactJS中未定义的
- 类型错误:无法读取未定义的属性“toString” - 为什么
- 未捕获的语法错误:读取JSON文件时出现意外的标记
- if, else if, and else"我的代码条件被错误读取
- 401未经授权的错误读取Azure移动服务表作为认证的用户(Javascript)
- node.js错误:读取ECONNRESET