2011-07-12 60 views
1

我正在使用MVC示例here,並繞過了PhoneGap聯繫人數據,並將其替換爲我自己的模型和商店。當我將一個列表添加到面板時,我將其指向myApp.stores.products。清單是一個數據視圖,所以tplstore,並要求itemSelector,但是例如省略itemSelector並使用itemTpl代替tpl ...添加了所需的DataView配置,但仍然出現錯誤? (tpl:vs itemTpl)

items: [{ 
     xtype: 'list', 
     store: myApp.stores.products, 
     itemTpl: '{productName}', 
     onItemDisclosure: function (record) { 
      //Ext.dispatch({ 
      // controller: myApp.controllers.products, 
      // action: 'show', 
      // id: record.getId() 
      //}); 
     } 
    }] 

當然,我得到一個控制檯的警告如下:

Uncaught DataView requires tpl, store and itemSelector configurations to be defined.

於是,我改變配置什麼,我知道它應該是現在得到一個錯誤......

items: [{ 
    xtype: 'list', 
    store: myApp.stores.products, 
    tpl: '{productName}', 
    itemSelector: 'div.productView', 
    onItemDisclosure: function (record) { 
     //Ext.dispatch({ 
     // controller: myApp.controllers.products, 
     // action: 'show', 
     // id: record.getId() 
     //}); 
    } 
}] 

Uncaught Error: Ext.List: itemTpl is a required configuration.

那麼,這是什麼? itemTpl或tpl?爲什麼Ext.List不知道要使用哪個?我甚至嘗試添加tplitemTpl,爲了安全起見,仍然得到了上述兩個錯誤中的第一個。

注: 這就是它看起來像在面板方面:

myApp.views.ProductList = Ext.extend(Ext.Panel, { 
    dockedItems: [{ 
     xtype: 'toolbar', 
     title: 'Products' 
    }], 
    items: [{ 
     xtype: 'list', 
     store: myApp.stores.products, 
     tpl: '{productName}', 
     itemSelector: 'div.productView', 
     onItemDisclosure: function (record) { 
      //Ext.dispatch({ 
      // controller: myApp.controllers.products, 
      // action: 'show', 
      // id: record.getId() 
      //}); 
     } 
    }], 
    initComponent: function() { 
     myApp.stores.products.load(); 
     myApp.views.ProductList.superclass.initComponent.apply(this, arguments); 
    } 
}); 

UPDATE: 我認爲這是barfing在initComponent.apply()...

myApp.views.ProductList.superclass.initComponent.apply(this, arguments); 

回答

1

好的。在Sencha Touch initComponent函數中放置一個斷點,我發現它與tpl或itemTpl完全沒有關係。不知何故,我的商店是未定義的。現在上一個新的謎...

該面板和列表正在創建時,該商店未定義。所以,最終的修正最終將轉換.js文件包含在index.html中的順序。現在工作就像一個幸運的魅力。

+0

很酷,謝謝! JS確實是一種特殊語言;) –

1

我有同樣的問題,但對我來說,問題來自於用於調用代理的變量名稱中存在錯誤:當需要使用小寫字母時,我輸入了大寫字母。 用您的代碼示例:我用myApp.stores.Products而不是myApp.stores.products

但它需要時間找到...

+0

是的。這是一個容易犯的錯誤,但很難發現。一個很好的約定是大寫類定義的第一個字母,並小寫對象實例的第一個字母。然後在任何一種情況下駱駝案(theRestOfTheLetters)。 –

+0

你是絕對正確的,這是我在Java項目中所做的,但我不知道爲什麼我沒有在我的Js PhoneGap項目中這麼做。 –

相關問題