2013-04-21 49 views
3

我是Sencha的新手,儘管我已經完成了大部分需要的工作,但我仍在努力完成一項特定任務 - 動態設置商店代理URL,以及加載/提供商店,當用戶點擊列表中的項目時。Sencha Touch - 動態設置商店代理網址,並將商店加載到商品列表中

我在這裏找到了解決這個問題的各種方法使用setProxy,代碼看起來很簡單,但我只是不能解決如何成功地將任何建議的代碼片段集成到我自己的代碼。因此,我在下面列出了我的代碼,如果有人能夠準確地告訴我需要包含什麼以及在哪裏,我將非常感激。

原始記錄列表(#grList)保存在導航視圖(Main.js)中。

Ext.define('Groups.view.Main', { 
extend: 'Ext.navigation.View', 
xtype: 'main', 
requires: [ 
], 
config: { 
    id: 'Main', 
    items: [ 
    { 
      xtype: 'tabpanel', 
      title: 'User Groups', 
      ui: 'light', 
      layout: { 
       animation: 'fade', 
       type: 'card' 
      }, 
      tabBar: { 
       docked: 'top', 
       layout: { 
        pack: 'center', 
        type: 'hbox' 
       } 
      }, 
      items: [ 
       { 
        xtype: 'list', 
        title: 'News', 
        id: 'rssList', 
        itemTpl: [ 
         '{title}<br/><small>{contentSnippet}' 
        ], 
        store: 'Feeds' 
       }, 
       { 
        xtype: 'list', 
        title: 'Profiles', 
        id: 'grList', 
        itemTpl: [ 
         '<img class="photo" src="{grCountryFlagURL}" align="center" width="40" height="40"/>{grHandle}<br/><small>{grCountry}</small>' 
        ], 
        store: 'Groups' 
       }, 
       { 
        xtype: 'carousel', 
        title: 'About', 
        items: [ 
         { 
          xtype: 'component', 
          html: '1' 
         }, 
         { 
          xtype: 'component', 
          html: '2' 
         } 
        ] 
       } 
      ] 
     } 


    ] 
} 

});

在點擊記錄項目時,控制器(MainController.js)將詳細面板(GroupDetail.js)推送到導航視圖。

Ext.define('Groups.controller.MainController', { 
extend: 'Ext.app.Controller', 

config: { 
    refs: { 
     main: '#Main' 
    }, 

    control: { 
     "#grList": { 
      itemtap: 'showGRDetail' 
     }, 
     "#rssList": { 
      itemtap: 'showRSSDetail' 
     } 
    } 
}, 

showGRDetail: function(dataview, index, target, record, e, eOpts) { 
    var GRdetail = Ext.create('Groups.view.GroupDetail'); 
    this.getMain().push(GRdetail); 
    GRdetail.setData(record.data); 
    GRdetail.getAt(0).setData(record.data); 
    GRdetail.getAt(1).setData(record.data); 
}, 
showRSSDetail: function(dataview, index, target, record, e, eOpts) { 
    var RSSdetail = Ext.create('Groups.view.NewsDetail'); 
    this.getMain().push(RSSdetail); 
    RSSdetail.setData(record.data); 
} 

});

詳細面板包含兩個選項卡。第一個是顯示記錄數據的簡單容器,工作正常。第二個(#rssGroup)是一個列表,我想在其中顯示特定於被點擊的記錄項目的RSS提要,但這是我無法工作的位。

Ext.define('Groups.view.GroupDetail', { 
extend: 'Ext.tab.Panel', 

config: { 
    id: 'GroupDetail', 
    items: [ 
     { 
      xtype: 'container', 
      padding: 30, 
      title: 'Profile', 
      iconCls: 'search', 
      id: 'grProfile', 
      tpl: [ 
       '<img class="photo" src="{grCountryFlagURL}" align="center" width="80" height="50"/>{grHandle}<br/><small>{grProfile}</small>' 
      ], 
      layout: { 
       type: 'fit' 
      } 
     }, 
     { 
      xtype: 'list', 
      title: 'News', 
      id: 'rssGroup', 
      iconCls: 'info', 
      itemTpl: [ 
      '{title}<br/><small>{contentSnippet}' 
      ], 
      store: 'GroupNews' 
       } 
    ], 
    tabBar: { 
     docked: 'bottom', 
     layout: { 
      pack: 'center', 
      type: 'hbox' 
     } 
    } 
} 

});

RSS列表使用商店(GroupNews.js)和模型(Feed.js),如果我在商店中設置autoload = true並且硬編碼靜態代理URL,但是如果關閉自動加載並且刪除prxy網址,我的實驗在動態設置,加載和服務這家商店都沒有工作。

Ext.define('Groups.store.GroupNews', { 
extend: 'Ext.data.Store', 
alias: 'store.GroupNews', 

requires: [ 
    'Groups.model.Feed' 
], 

config: { 
    autoLoad: false, 
    model: 'Groups.model.Feed', 
    storeId: 'GroupNews', 
    proxy: { 
     type: 'jsonp', 
     url: '', 
     reader: { 
      type: 'json', 
      rootProperty: 'responseData.feed.entries' 
     } 
    } 
} 

});

Nb。我沒有在上面的代碼示例中包括我嘗試動態設置/加載GroupNews商店的任何嘗試,這正是我迄今爲止所做的工作。

任何幫助將非常感激。

回答

5

你試過嗎? -

var group_store = Ext.getStore("GroupNews"); 
group_store.getProxy().setUrl('new_url_here');  
group_store.load(); 

而且如果店裏代理URL被改變,它加載指定商店列表再次 -

your_list.setStore(group_store); 

,那麼你就可以看到group_store.getCount()方法的項目數量只是爲了確保你有正確的數據。

+0

我嘗試了幾件非常相似的事情,但沒有成功,但第一次工作,非常感謝回覆,這真的幫了我很多。 – Will 2013-04-21 10:21:56

+0

我猜想加載存儲的部分再次被更改的代理丟失,或者將新加載的商店分配給要列出的數據。如果你想確定發生了什麼問題,只需嘗試評論這兩行中的一行。 – SachinGutte 2013-04-21 10:40:58