2013-02-28 57 views
0

我想使用.setActiveItem在Sencha 2.1 MVC應用程序中顯示listview(Ext.dataview.List)中項目的詳細信息。問題是我無法獲得加載數據的詳細視圖。將數據加載到列表中的詳細視圖sencha touch 2 MVC

我已經嘗試了很多不同的方法來獲取詳細視圖來顯示數據,包括setData,setRecord和Update(請參閱下面的一些我的最新嘗試)。

我在搜索論壇,stackoverflow和谷歌搜索時得到的大部分結果都是針對不使用MVC模型的sencha應用程序。 (哦,使用.push,這工作正常,但由於其他原因,我要離開導航視圖)。

從我的控制器:

showDetail: function(list, record) { 
    /*this.getMain().push({ 
     xtype: 'labdetail', 
     title: record.fullName(), 
     data: record.getData() 
    });*/ 
//The code above works, but only as long as I stay with navigation view... 
    console.log("showDetail"); 
     //Ext.getCmp('labdetail').update(record.data); 
     //LabDetail.update(record.data); 
     //Ext.fly('labdetail').setData(record.data); 
     //Ext.getCmp('labdetail').setData(record.data); 
     //Ext.component('Labblistan.view.LabDetail').destroy(); 
     //Ext.getCmp('Labblistan.view.LabDetail').destroy(); 
     //Ext.fly('labdetail').destroy(); 
     //var DetailView = Ext.create('Labblistan.view.LabDetail'); //If I create the view the console complains I need to destroy previous views with the same ID, hence the different destroy() approaches above 
     //DetailView.setRecord(record); 
     Ext.getCmp('mainpanel').setActiveItem('labdetail'); //This navigates to the right view, but it's empty 
}, 

我的DetailView:

Ext.define('Labblistan.view.LabDetail', { 
extend: 'Ext.Panel', 
xtype: 'labdetail', 
id: 'labdetail', 
config: { 
    title: '{Analysis}', 
    styleHtmlContent: true, 
    scrollable: 'vertical', 
    fullscreen: true, 
    tpl: [ 
     '<div style=position:absolute;top:50px;><p>Info about {Analysis}</p><p>{Comment}</p></div>' 
    ], 
     }, 
}); 

回答

0

不知道這是不是最好的做法,但是這是我得到它的工作:

Ext.getCmp('mainpanel').setActiveItem({ 
     xtype: 'labdetail', 
     title: 'Detaljinformation', 
     data: record.getData() 
}); 
+0

這看起來很好。我也這樣做:我通常爲自定義視圖提供一個'record'配置,然後在'applyRecord'中執行'this.setData(record.getData())',但最後它是一樣的。 – 2013-03-08 06:04:14

相關問題