我是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> </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');
}
}
但看起来只能使用一次,无论如何,正如作者所说,它可能导致内存泄漏。任何人都可以给我任何建议吗?提前谢谢你!
答案 0 :(得分:0)
而不是在视图中声明事件你可以在Controller..like中声明应该工作尝试在这里列表视图名称是结果你可以声明你已创建的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');
}
});