0

我嘗試了一些不同的東西,但無法將數據從控制器傳遞到視圖(到容器內的組件)。我無法將數據從控制器傳遞到Sencha Touch中的視圖2.4

這裏我的觀點ServisDetail.js

Ext.define('Asistan.view.ServisDetail', { 
    extend: 'Ext.Container', 
    xtype: 'servisDetail', 
    config: { 
     layout: 'fit', 
     items : [ 
      { 
       xclass : 'Asistan.view.ServisToolbar' 
      }, 
      { 
       // "data: {}" is needed to work. I try to pass data from controller to here 
       xtype: 'component', 
       tpl: Ext.create('Ext.XTemplate','{URUN_CIHAZ_ADI} jkjk') 
      } 
     ] 
    } 
}); 

這裏是我的控制器Servis.js認爲認爲它應該工作。但它沒有通過數據:

Ext.define('Asistan.controller.Servis', { 
    extend: 'Ext.app.Controller', 
    config: { 
     refs: { 
      servis: 'servisNavigationView servisContainer list', 
     }, 
     control: { 
      servis: { 
       itemdoubletap: 'showServis' 
      } 
     } 
    }, 
    showServis: function(item, index, e, eOpts) { 
     this.servis = Ext.widget('servisDetail'); 
     this.servis.config.items[1].data = eOpts.data; // <- Here! It doesn't work. console.log shows that the data is there but in the browser the data doesn't show up. 
     console.log(this.servis.config.items[1].data); // I can see my data here, right before the push 
     item.up('servisNavigationView').push(this.servis); 
    } 
}); 

我失蹤了什麼?

回答

0

該項目與tpl應該有一個id嘗試。

{ 
    id: 'itemWithTpl', // <- here 
    xtype: 'component', 
    tpl: Ext.create('Ext.XTemplate','{URUN_CIHAZ_ADI} jkjk') 
} 

而且,所述控制器:

showServis: function(item, index, target, record, e, eOpts) { 
    this.servis = Ext.widget('servisDetail'); 
    item.up('servisNavigationView').push(this.servis); 
    Ext.getCmp('itemWithTpl').setData(record.data); // <- here 
} 
1

使用

showServis: function(item, index, e, eOpts) { 
    this.servis = Ext.widget('servisDetail'); 
    this.servis.setData(eOpts.data); // setData applies the data to the container template. 
    item.up('servisNavigationView').push(this.servis); 
} 
+0

您的代碼的數據發送到所述容器,不與'tpl'的組件。 – ilhan

+1

您應該避免在Sencha Touch應用程序中使用Ext.getCmp()。如果頁面中有多個組件實例,則會遇到問題。改用Ext.ComponentQuery方法。 –

+0

我寧願使用itemId代替id,以便可以銷燬視圖並重新創建它們。 – Dinkheller

相關問題