关联模型

时间:2011-09-18 05:24:45

标签: extjs4

我收到错误:

Uncaught TypeError: Cannot call method 'indexOf' of undefined
Ext.apply.urlAppend ext-all-debug.js:5040
Ext.define.buildUrl ext-all-debug.js:26324
Ext.define.buildRequest ext-all-debug.js:26148
Ext.define.doRequest ext-all-debug.js:26367
Ext.define.read ext-all-debug.js:26117
Ext.define.inheritableStatics.load ext-all-debug.js:26603
(anonymous function) ext-all-debug.js:51162
(anonymous function) test.html:89
isEvent ext-all-debug.js:10117
call ext-all-debug.js:10073

我不知道什么是担心。我已经检查了FF中的实例结构,它确实有函数getCategory。 谢谢!

        Ext.define("Category", {
            extend: "Ext.data.Model",
            fields: ["id", "name"]
        });
        Ext.define("Product", {
            extend: "Ext.data.Model",
            fields: ["id", "name", "category_id"],
            associations: [{
                type: "belongsTo",
                model: "Category",
                primaryKey: "id",
                foreignKey: "category_id",
                associationKey: "category"
            }]
        });

        Ext.onReady(function(){
            var p = new Product({
                id: 1,
                name: "Kotomi",
                category_id: 2,
                category: {
                    id: 2,
                    name: "Clannad"
                }
            });
            console.log(p.getCategory().get("name"));
        });

1 个答案:

答案 0 :(得分:0)

这是documentation of ExtJs 4的样本。你误导了下面的句子:

The getCategory function was created on the Product model when we defined the 
association. This uses the Category's configured proxy  to load the Category
asynchronously, calling the provided callback when it has loaded.

因此,此错误是由于在类别模型中缺少代理配置。