我正在努力学习Backbone.js
它有工作GET,PUT和DELETE单一模型.但是,当我创建一个集合时,fetch方法会给出以下错误:Uncaught TypeError:无法读取未定义的属性'idAttribute'(backbone.js:683)
这是我正在尝试的代码:
Person = Backbone.Model.extend({
urlRoot: '/people'
});
PersonList = Backbone.Collection.extend({
model: 'Person',
url: '/people'
});
var personList = new PersonList();
personList.fetch();
Run Code Online (Sandbox Code Playgroud)
在获取时,服务器返回以下JSON,我认为这是正确的:
[{"id":1,"name":"Matt","description":"Worker"},{"id":3,"name":"Test","description":"Test person"}]
Run Code Online (Sandbox Code Playgroud)
我使用的是jQuery 2.0.3(也尝试过1.10.2),Underscore.js 1.5.2和Backbone.js 1.1.0
我究竟做错了什么?
我正在尝试克隆引用另一个模型的模型,但我得到:Error: [mobx-state-tree] Failed to resolve reference 'H1qH2j20z' to type 'AnonymousModel' (from node: /usualCustomer)...
在克隆中。原版解决没问题。
这是我的模型:
const Job = types.model({
id: types.optional(types.identifier(types.string), shortid.generate()),
jobNumber: types.optional(types.string, ''),
description: '',
usualCustomer: types.maybe(types.reference(Customer)),
})
const Customer = types.model({
id: types.optional(types.identifier(types.string), shortid.generate()),
name: types.optional(types.string, 'New customer'),
})
Run Code Online (Sandbox Code Playgroud)
这个函数说明了问题:
editJob = job => {
console.log('Original', job)
var newClone = clone(job)
console.log('Clone', newClone)
}
Run Code Online (Sandbox Code Playgroud)