2013-02-28 23 views
0

我對Sencha非常陌生,我試圖在Panel中的DataView下獲得按鈕。我嘗試過不同的場景。Sencha - 將DataView與按鈕組合在同一視圖中

Ext.define('MyApp.view.Profile', { 
extend : 'Ext.Panel', 
xtype : 'profileview', 

requires : ['MyApp.store.UserStore', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'], 

initialize : function() { 
    var me = this; 
    var record = 1; 
    //Create the instance of the store and load it 
    var userStore = Ext.create('MyApp.store.UserStore'); 
    userStore.load(); 

    //Create the dataview 
    var view = Ext.create('Ext.DataView', { 
     store : userStore, 
     itemTpl : ['<h1>Mijn Profiel</h1>', '<h2>{USERNAME}</h2>', '<p>{EMAIL}</p><br/>', '<img src="http://www.MyApp.nl/{AVATAR_PATH}" />', '<br/>'].join() 
    }); 
    //Add the dataview to the panel 
    me.add(view); 

    /** 
    var button = Ext.create('Ext.Button', { 
    text : 'Edit', 
    handler : function() { 
    Ext.Msg.alert('You clicked the button'); 
    } 
    }); 
    */ 
    //me.add(button); 

}, 

config : { 
    title : 'Profiel', 
    iconCls : 'user3', 
    scrollable : true, 
    styleHtmlContent : true, 
    items : [{ 
     xtype : 'button', 
     text : 'Edit', 
     handler : function() { 
      Ext.Msg.alert('You clicked the button'); 
     } 
    }] 
} 
}); 

上面視圖僅示出了按鈕,但不是數據視圖。我需要添加

layout : 'fit' 

到配置使它顯示DataView。但與按鈕組合使按鈕全屏,數據視圖不再顯示(???)。

我試了兩種情況下,我添加一個按鈕作爲配置項目,並通過使用處理程序。

如何獲得數據視圖下方的按鈕?

感謝您的幫助。

+0

嘗試給底部:「10px的」以按鈕,讓我知道 – 1Mayur 2013-02-28 10:46:51

+0

沒有工作,所以我加了一個高度屬性設置按鈕,現在我看到了,但按鈕位於頂部並覆蓋數據視圖(??) – 2013-02-28 11:28:12

回答

1

不要使用佈局擬合,它是爲了適合您的畫布中的一個組件。我會使用vbox佈局。這會自動將項目置於對方之下。

試試這個:

layout: { 
    type: 'vbox', 
    align: 'stretch' //this tells to take the full width 
} 

彎曲你的數據視圖

var view = Ext.create('Ext.DataView', { 
    flex: 1, //Use the remaining space. 
    store : userStore, 
    itemTpl : ['<h1>Mijn Profiel</h1>', '<h2>{USERNAME}</h2>', '<p>{EMAIL}</p><br/>', '<img src="http://www.MyApp.nl/{AVATAR_PATH}" />', '<br/>'].join() 
}); 
+0

嗨Johan,這確實顯示了dataview,但現在它在按鈕下面。如何顯示數據視圖下方的編輯按鈕? – 2013-02-28 17:24:38

+0

你必須使用'insert'而不是'add'。所以:'me.insert(0,view);'http://docs.sencha.com/touch/2-1/#!/api/Ext.Panel-method-insert – 2013-03-01 07:34:49

相關問題