Javascript ExtJS 4.2.1-使用关联的getter/setter无效
我在尝试调用与另一个模型有关联的模型对象上的getter/setter时遇到问题。以下是课程: Category.jsJavascript ExtJS 4.2.1-使用关联的getter/setter无效,javascript,extjs,associations,setter,getter,Javascript,Extjs,Associations,Setter,Getter,我在尝试调用与另一个模型有关联的模型对象上的getter/setter时遇到问题。以下是课程: Category.js Ext.define('Chapter05.model.Category', { extend: 'Ext.data.Model', fields: [ { name: 'id', type: 'int' }, { name: 'name', type: 'string' } ] }) Product.js Ext.
Ext.define('Chapter05.model.Category', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' }
]
})
Product.js
Ext.define('Chapter05.model.Product', {
extend: 'Ext.data.Model',
requires: [
'Chapter05.model.Category'
],
fields: [
{ name: 'id', type: 'int' },
{ name: 'category_id', type: 'int' },
{ name: 'name', type: 'string' }
],
// we can use the belongsTo shortcut on the model to create a belongsTo association
associations: [
{ type: 'belongsTo', model: 'Chapter05.model.Category' }
]
})
Main.js
Ext.define('Chapter05.view.Main', {
extend: 'Ext.container.Container',
requires:[
'Ext.tab.Panel'
'Chapter05.model.Product',
'Chapter05.model.Category',
],
xtype: 'app-main',
layout: 'vbox',
items: [
{
xtype: 'button',
text: 'Category',
handler: function(evt) {
var product = new Chapter05.model.Product({
id: 100,
category_id: 20,
name: 'Sneakers'
});
product.getCategory(function(category, operation) {
// do something with the category object
alert(category.get('id')); // alerts 20
}, this);
}
}
]
});
错误发生在product.getCategory(…)所在的行。我在Safari Web Inspector中收到以下消息:
TypeError: 'undefined' is not a function (evaluating 'product.getCategory')
我忘记做什么了吗
附言。
项目(第05章)是使用Sencha Cmd生成的。因此,完全限定名。我在
hasOne
关系中遇到了类似的问题。通过自己指定getter/setter和associationKey解决了这个问题
比如:
belongsTo: {
model: 'Chapter05.model.Category',
getterName: 'getCategory',
setterName: 'setCategory',
associationKey: 'category_id'
}
我添加了您文章中的所有内容,但现在我收到了以下错误:Ext.data.proxy.Server.buildUrl():您使用的是服务器代理,但没有为其提供url。在谷歌上进行了快速搜索,并尝试将idProperty字段添加到两个模型中。还是有同样的错误。有什么想法吗?