Sencha和Phonegap回调问题

时间:2014-03-07 02:19:26

标签: sencha-touch-2.2

这就是我创建xtype的方式。但这根本不起作用,getImageData根本没有被调用。有人可以对此有所了解吗?

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();                                    
                            }
                        }
                    ]                                           
                }
            ]

2 个答案:

答案 0 :(得分:1)

你试过了吗?

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

我的意思是,无论如何,“图像”已经在其武器库中获得了“点击”事件..

答案 1 :(得分: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'
                        }
                    ]
                }
            ]
        }
相关问题