0

我是 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;
           },
    },

另外,我在 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');
        }
    }

但它看起来只能使用一次,无论如何,正如作者所说,它可能导致内存泄漏。所以任何人都可以给我任何建议吗?提前谢谢你!

4

1 回答 1

0

而不是在视图中声明事件,您可以在 Controller 中声明 .. 如下所示应该可以在这里尝试列表视图名称是结果,您可以声明您创建的 wat ..

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

                }
                });
于 2013-10-23T08:50:19.840 回答