简体   繁体   English

如何在Sencha Touch 2中区分列表的itemtap和itemtaphold事件

[英]How to distinguish list's itemtap from itemtaphold event in Sencha Touch 2

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: 我是Sencha Touch 2的新手,今天我遇到一个问题,我想在列表的侦听器中添加itemtap和itemtaphold事件,但是在触发itemtaphold时我无法禁用itemtap。通常,我会使用像dataView.config这样的变量.istplhold在控制器中进行区分,但在侦听器中不起作用。这是我的代码:

    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: 另外,我在Sencha论坛中看到了另一个解决方案:

    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! 但是它看起来只能使用一次,正如作者所说,这可能会导致内存泄漏。所以有人可以给我任何建议吗?谢谢!

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 .. 而不是在视图中声明事件,您可以在Controller..like中声明,如下所示,可以在这里尝试工作:列表视图名称是结果,您可以声明已创建的..

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');

                }
                });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM