2014-03-07 57 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(); 
    } 
] 

我的意思是, “图像” 已经有了它的兵工厂反正 “自来水” 事件..