2013-03-11 84 views
0

我使用以下Xtemplate濾除由類別項(見視圖/面板,其中它是「容納」下面):ExtJS的xtemplate過濾空白行

itemTpl: new Ext.XTemplate(
    '<tpl for=".">', 
     '<tpl if="category === \'vegetable\'">', 
      '<a href="" target="">{str}</a>', 
     '</tpl>', 
    '</tpl>'), 

和如預期被過濾(井,至少部分)。

我有以下商店:

Ext.define("Produce.store.List", { 
    extend: 'Ext.data.Store', 
    alias: 'store.List', 
    config: { 
     model: 'Produce.model.Food', 
     sorters: 'category', 
     grouper: function(record) { 
      return record.get('category')[0]; 
     }, 
     data: [ 
     { category: 'fruit', str: 'tomato'}, 
     { category: 'fruit', str: 'green bean'}, 
     { category: 'vegetable', str: 'celery'}, 
     { category: 'vegetable', str: 'sprouts'}, 
     { category: 'fruit', str: 'squash'}, 
     { category: 'fruit', str: 'snap peas'}, 
     { category: 'vegetable', str: 'rhubarb'}, 
     { category: 'vegetable', str: 'cabbage'} 

     ] 
    } 
}); 

的Xtemplate在以下視圖/面板呈現:

Ext.define('Produce.view.Vegetable', { 
    extend: 'Ext.tab.Panel', 
    requires: ['Produce.model.Food'], 
    config: { 
     tabBar: { 
      docked: 'top', 
      ui: 'neutral', 
      layout: { 
       pack: 'center' 
      } 
     }, 
     items: [{ 
      title: 'Produce', 
      layout: Ext.os.deviceType == 'Phone' ? 'fit' : { 
       type: 'vbox', 
       align: 'center', 
       pack: 'center' 
      }, 
      cls: 'demo-list', 
      items: [{ 
       width: Ext.os.deviceType == 'Phone' ? null : 300, 
       height: Ext.os.deviceType == 'Phone' ? null : 500, 
       xtype: 'list', 
       store: 'List', 
     itemTpl: new Ext.XTemplate(
     '<tpl for=".">', 
      '<tpl if="category === \'vegetable\'">', 
       '<a href="" target="">{str}</a>', 
      '</tpl>', 
     '</tpl>'), 
       variableHeights: false 
      }] 
    } 
}); 

當運行此只在存儲中的蔬菜被顯示在面板 - 這是很棒的 - 但空白行也顯示在水果項目在渲染列表中被過濾出來 - 這並不好。 (同樣,在我的「水果」觀點中,水果按需要顯示,但在有蔬菜的地方,空白行顯示出來)。

我該如何擺脫這些空白行(這是一個問題,因爲我的清單中的水果和蔬菜只是爲了讓應用程序工作,並且是填充以表示更大量的記錄將被分類爲我的實際應用程序)。我嘗試使用Ext.IsEmpty和null過濾,但這些都沒有把戲。

回答

0

該視圖運行良好:它顯示每條記錄的一行。您應該嘗試將已過濾的商店添加到列表中。

看看在Sencha Touch documentation

這將解決您的問題!

+0

我會使用一個過濾器,但如果我在另一個視圖(特別是蔬菜視圖)中使用該商店,我打算這麼做,我不會獲得完整的商店內容。 – 2013-03-11 15:04:58

+0

沒關係,我看到我可以在渲染視圖之前做一個clearFilter。我稍後會嘗試一下,並告訴你它是如何工作的。 GRAZI! – 2013-03-11 15:25:23

+0

就像蝙蝠一樣的魅力!丹科舒恩! – 2013-03-12 00:35:26