2011-09-18 204 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.

所以,這個錯誤是因爲在分類模型缺少代理配置的。