2013-04-07 77 views
2

我試圖改變使用setSrc圖像的來源,但我得到這個錯誤: 遺漏的類型錯誤:無法調用「setSrc」的未定義SenchaTouch:Ext.getCmp()setSrc()方法不能正常工作

Ext.Ajax.request.success Ext.apply.callback Ext.define.onComplete Ext.define.onStateChange (anonymous function)

這是我的源代碼: 查看頁:

Ext.define('MechanicalTerk.view.Picture', { 
extend: 'Ext.Container', 
xtype: 'Picture', 
requires: [ 
    'Ext.data.Store' 
], 
config: { 
    layout: 'vbox', 
    items: 
    [ 
     { 
      xtype: 'toolbar', 
      docked: 'top', 
      title: 'Requests', 
      minHeight: '60px', 
      items: [ 
       { 
        xtype:'button', 
        ui:'back button', 
        id:'backButton', 
        text:'Back' 


       },{ 
        xtype: 'button', 
        id:'logoutButton', 
        text: 'Logout' 
       } 
      ],   
     }, 


     { 
      xtype:'image', 
      height:500, 
      id:'layoutImage' 
     } 
    ] 
} 
}); 

控制器:

Ext.define('MechanicalTerk.controller.PictureController',{ 
extend:'Ext.app.Controller', 
showPicture: function(userID,sentAt){ 
    Ext.Ajax.request({ 
     url:'app/Model/database.php', 
     params: { 
      functionID: 3, 
      userID: userID, 
      sentAt: sentAt, 
     }, 
     success: function (response, opts){ 
Ext.getCmp('layoutImage').setSrc('http://www.sencha.com/img/20110215-feat-perf.png'); 
Ext.Viewport.setActiveItem(Ext.create('MechanicalTerk.view.Picture')); 
      } 
     }); 
    } 
}); 

任何想法?

回答

0

您應該考慮不要使用自己的id,而應使用itemId。這可能是因爲您試圖重新使用已銷燬的組件。我建議在您的控制器中爲您的圖像創建一個ref,以便您可以訪問它。

所以我想:

Ext.define('MechanicalTerk.controller.PictureController',{ 
    extend:'Ext.app.Controller', 

    config: { 
     refs : { 
      myImage : { 
       autoCreate: true, 
       selector: '#myimage',//assuming your image's itemId is 'myimage' 
       xtype: 'image' 
      } 
     } 
    }, 
    showPicture: function(userID,sentAt){ 
     Ext.Ajax.request({ 
      url:'app/Model/database.php', 
      params: { 
       functionID: 3, 
       userID: userID, 
       sentAt: sentAt, 
      }, 
      success: function (response, opts){ 
       var me = this; 
       me.getMyImage().setSrc('http://www.sencha.com/img/20110215-feat-perf.png'); 
       Ext.Viewport.setActiveItem(Ext.create('MechanicalTerk.view.Picture')); 
      } 
     }); 
    } 
}); 

PS:未經測試,但嘗試這種方法。