Sencha touch 2 Sencha touch 2自定义列表项按钮点击未触发

Sencha touch 2 Sencha touch 2自定义列表项按钮点击未触发,sencha-touch-2,custom-component,mobile-application,Sencha Touch 2,Custom Component,Mobile Application,我正在sencha touch 2上开发一款混合移动应用程序。 现在,我需要一个自定义组件来指定一个自定义列表项,该列表项由一个按钮和一个按钮组成 我的视图已按我所希望的方式呈现,但添加到列表项的按钮未按预期触发点击事件。相反,每次点击都会触发ITEMTAP事件,这会造成一点混乱 有人能建议我去哪里做这项工作吗 下面是我创建的自定义组件的代码: var listView = { xtype : "list", id : "desk-list-sea

我正在sencha touch 2上开发一款混合移动应用程序。 现在,我需要一个自定义组件来指定一个自定义列表项,该列表项由一个按钮和一个按钮组成

我的视图已按我所希望的方式呈现,但添加到列表项的按钮未按预期触发点击事件。相反,每次点击都会触发ITEMTAP事件,这会造成一点混乱

有人能建议我去哪里做这项工作吗

下面是我创建的自定义组件的代码:

var listView = {
            xtype : "list",
            id : "desk-list-search-results",
            cls : "desk-list-search-results-cls",
            selectedCls : "",
            defaultType:"desksearchlistitem",
            store : "deskstore",
            flex : 2
        };
这是自定义组件的代码

Ext.define("MyApp.view.DeskSearchListItem",{
    extend:"Ext.dataview.component.ListItem",
    requires:["Ext.Button"],
    alias:"widget.desksearchlistitem",
    initialize:function()
    {
        this.callParent(arguments);
    },
    config:{
        layout:{
            type:"hbox",
            align:"left"
        },
        cls:'x-list-item desk-search-list-item',
        title:{
            cls:"desk-list-item",
            flex:0,
            styleHtmlContent:true,
            style:"align:left;"
        },
        image:{
            cls:"circle_image",
            width:"28px",
            height:"28px"
        },
        button:{
            cls:'x-button custom-button custom-font bookdesk-button',
            flex:0,
            text:"Book",
            width:"113px",
            height:"46px",
            hidden:true
        },
        dataMap:{
            getTitle:{
                setHtml:'title'
            }
        }
    },
    applyButton:function(config)
    {
        return Ext.factory(config,Ext.Button,this.getButton());
    },
    updateButton:function(newButton,oldButton)
    {
        if(newButton)
        {
            this.add(newButton);
        }

        if(oldButton)
        {
            this.remove(oldButton);
        }
    },
    applyTitle:function(config)
    {
        return Ext.factory(config,Ext.Component,this.getTitle());
    },
    updateTitle:function(newTitle,oldTitle)
    {
        if(newTitle)
        {
            this.add(newTitle);    
        }
        if(oldTitle)
        {
            this.remove(oldTitle);
        }
    },
    applyImage:function(config)
    {
        return Ext.factory(config,Ext.Component,this.getImage());
    },
    updateImage:function(newImage,oldImage)
    {
        if(newImage)
        {
            this.add(newImage);
        }
        if(oldImage)
        {
            this.remove(oldImage);
        }
    }
})

终于找到了解决办法

可以使用listeners对象在视图中执行此操作

下面是它的代码示例

listeners:{
                initialize:function()
                {
                    var dataview = this;
                    dataview.on("itemtap",function(list,index,target,record,event){
                        event.preventDefault();
                    });
                    dataview.on("itemswipe",function(list,index,target,record,event){
                        if(event.direction === "right")
                        {
                            var buttonId = target.element.down(".bookdesk-button").id;
                            var buttonEl = Ext.ComponentQuery.query("#"+buttonId)[0];
                            if(Ext.isObject(buttonEl))
                            {
                                buttonEl.setZIndex(9999);
                                buttonEl.show({
                                    showAnimation:{
                                        type:"slideIn",
                                        duration:500
                                    }
                                });
                                var listeners = {
                                    tap:function(btn,e,opt)
                                    {
                                        console.log("Button Tapped");
                                    }
                                };

                                buttonEl.setListeners(listeners);

                            }
                            else
                            {
                                console.log("This is not a valid element");
                            }
                        }
                    });
                }
            }
谢谢你