2014-03-07 55 views
0

這是我如何創建一個xtype。但是這根本不起作用,getImageData根本沒有被調用。有人可以對此有所瞭解嗎?Sencha和Phonegap回調問題

items: [ 
       { 
        xtype: 'image', 
        flex: 9, 
        height: '100px', 
        itemId: 'imageFieldData', 
        width: '100px', 
        src:'resources/images/icon_camera.png', 
        getImageData : function() 
        {       
         if(Ext.browser.is.PhoneGap) 
         { 
          navigator.camera.getPicture(this.setImageData, function(message){console.log(message);}, { quality: 50 }); 
         } 
        }, 
        setImageData : function(imageData){ 
         console.log("data:image/jpeg;base64," + imageData); 
         console.log(t); 
         console.log(this); 
         this.setSrc(imageData);       
        }, 
        listeners:[ 
         { 
          element: 'element', 
          event: 'tap',        
          fn: function(e,t) {         
           this.getImageData();          
          } 
         } 
        ]           
       } 
      ] 
+0

有任何錯誤消息? – Fazil

+0

@Fazil我沒有得到任何錯誤消息。我在genymotion模擬器上運行此代碼並通過weinre進行調試。沒有錯誤 – Kathir

回答

0

我修改了一些代碼以添加更多的功能,使用按鈕從相機拍照並從畫廊中選擇。這是代碼,它的工作原理。

{ 
      xtype: 'panel', 
      height: '100px', 
      width: '70%', 
      layout: 'hbox', 
      items: [ 
       { 
        xtype: 'image', 
        flex: 1, 
        height: '100px', 
        itemId: 'imageFieldData', 
        id:'imageFieldData', 
        width: '100px', 
        margin:'5px', 
        src:'resources/images/icon_camera.png'              
       }, 
       { 
        xtype: 'panel', 
        layout:'vbox', 
        flex:1, 
        items : [ 
         { 
          xtype:'spacer' 
         }, 
         { 
          xtype: "button", 
          text: "Choose From Gallery", 
          handler: function() { 
           function success(image_uri) { 
            var img = Ext.ComponentQuery.query("#imageFieldData")[0]; 
            img.setSrc(image_uri); 
           } 

           function fail(message) { 

           } 

           navigator.camera.getPicture(success, fail, 
            { 
             quality: 50, 
             destinationType: navigator.camera.DestinationType.FILE_URI, 
             sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY 
            } 
           ); 
          } 
         }, 
         { 
          xtype:'spacer' 
         }, 
         { 
          xtype: "button", 
          text: "Take Picture", 
          handler: function() { 
           function success(image_uri) { 
            var img = Ext.ComponentQuery.query("#imageFieldData")[0]; 
            img.setSrc(image_uri); 
           } 

           function fail(message) { 

           } 

           navigator.camera.getPicture(success, fail, 
            { 
             quality: 50, 
             destinationType: navigator.camera.DestinationType.FILE_URI, 
             sourceType : navigator.camera.PictureSourceType.CAMERA 
            } 
           ); 
          } 
         }, 
         { 
          xtype:'spacer' 
         } 
        ] 
       } 
      ] 
     } 
1

你嘗試過:

listeners:[ 
    tap: function(e,t) { 
     this.getImageData(); 
    } 
] 

我的意思是, 「圖像」 已經有了它的兵工廠反正 「自來水」 事件..