Question

I'm new to Sencha Touch 2.Today I encountered a problem,I want to add itemtap and itemtaphold events in a list's listeners,but I can't disable itemtap when itemtaphold fired.Usually,I would use a variable like dataView.config.istplhold to make this distinction in controller,but it doesn't work in listeners.Here is my code:

    itemTpl: ['<table><tr>'+
          //'<td>{attachmentName}</td>'+
         '<td width="40px;">{i}</td>'+
         // '<td ><a  href="http://10.1.71.240:8080/tyoa/page/phone/request/leader/upload.jsp?attachmentId={attachid}&attachmentName={attachmentName}"  id="uploadFile" style="text-decoration:none;">{attachmentName}({attachmentSize})</a></td></div>'+
         '<td style="word-wrap:break-word;word-break:break-all;"><a style="text-decoration:none;">{attachmentName}({attachmentSize})</a></td>'+
         '<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>'+
         '<td style="white-space:nowrap;"><span id="'+'{attachid}'+'test_002" style="color:#FFCC00;"></span></td>'+ 
         '</tr></table>',   
     ].join(''),
    listeners:{
          itemtap:function(dataView, index, target, record, e, eOpts){
             //alert("download");
             if (!dataView.config.istplhold){
                var attachId=record.get('attachid');
                var attachName=record.get('attachmentName');
                // alert("attachId: "+attachId);
                //alert("attachName: "+attachName);
                $('#'+attachId+'test_002').text("Downloding...");
                window.downloader.downloadFile(Global.proxyPortAndIP+"/tyoa/temp/"+attachId+"?"+attachName, {overwrite: true},
                    function(res){
                        $('#'+attachId+'test_002').text(res.progress+"%");
                        if(res.progress==100){
                            Ext.Msg.alert(attachName,"Downloading complete");
                            $('#'+attachId+'test_002').text("Download complete");
                        }
                    },function(error){
                        alert(error);
                        $('#'+attachId+'test_002').text("Download failed");
                    }
                );
             }else{
                dataView.config.istplhold = false;
             }
           },

           itemtaphold:function(dataView, index, target, record, e, eOpts){
                var control = this;
                // if (Global.istaphold){
                    this.actions = Ext.Viewport.add({
                        xtype : 'actionsheet',
                        items : [{
                            text : 'Delete',
                            scope : this,
                            handler : function() {
                                Ext.Msg.confirm("Delete", "Are you sure to delete this item?", function(text) {
                                    if (text == 'yes') {
                                        // control.deleteContent(record.get('attachid'));
                                        var docbaseAttachmentId=record.get('attachid');
                                        Ext.data.JsonP.request({
                                            url : Global.API + '/docbase/docbaseListDelete.jsp',
                                            callbackKey : 'callback',
                                            params : {
                                                id : docbaseAttachmentId,
                                                format : 'json',
                                            },
                                            success : function(result) {
                                                reg = result[0].reg;
                                                if (reg == 'true') {
                                                    Ext.Msg.alert("", "Item deleted");
                                                }
                                                storeDocuments = Ext.getStore('docbaseAttachments');
                                                recordIndex = storeDocuments.findExact('attachid',docbaseAttachmentId);
                                                storeDocuments.removeAt(recordIndex);
                                                storeDocuments.sync();
                                            },
                                        });
                                    }
                                });
                                this.actions.hide();
                            }
                        },{
                            text : 'Modify',
                            scope : this,
                            handler : function() {
                                this.actions.hide();
                                // control.updateDocbaseListDetail(record);
                                view =Ext.create('tyoa.view.more.docbase.DocbaseListDetailPanel');
                                view.setRecord(record);
                                viewDirectionLeft(view);
                            }
                        },
                        {
                            xtype : 'button',
                            text : 'Cancel',
                            scope : this,
                            handler : function() {
                                this.actions.hide();
                            }
                        }]
                    });
                    this.actions.show();
                // }
                dataView.config.istplhold = !dataView.config.istplhold;
           },
    },

Also,I see another solution in Sencha Forum:

    listeners : {
        itemtap : function(list) {
            if (!list.lastTapHold || (list.lastTapHold - new Date() > 1000)) {
                console.log('itemtap');
            }
        },
        itemtaphold : function(list) {
            list.lastTapHold = new Date();
            console.log('itemtaphold');
        }
    }

but it looks can only be used once,anyway,as the author said,it could lead to a memory leak.So can anyone give me any suggestion?Thank you in advance!

Was it helpful?

Solution

instead of declaring events in view you can declare in Controller..like below should work try here list view name is result u can declare wat u have created ..

Ext.define('MyApp.controller.Scanner', {
    extend: 'Ext.app.Controller',
    config: {
       control: {

            'Result list':{
                itemtap:'resultap',
                itemtaphold :'resulthold'
            }
        }
    },
    resultap:function(view, index, target, record, event){
                        alert('tap');
                    },
    resulthold:function(view, index, target, record, event){
                alert('taphold');

                }
                });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top