2011-09-18 161 views
3

我得到的错误:关联模型

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")); 
     }); 

回答

0

这是documentation of ExtJs 4的样本。你已经missleaded句子吼叫:

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.

所以,这个错误是因为在分类模型缺少代理配置的。