当前位置: 首页 > 知识库问答 >
问题:

如何向列表的每一行添加按钮?

万承志
2023-03-14

如何将Sencha按钮添加到列表的每一行?我在图像中添加了文本占位符,以说明按钮应该放在哪里。

Ext.application({
    launch: function() {
        var view = Ext.Viewport.add({
            xtype: 'navigationview',

            items: [
                {
                    xtype: 'list',
                    title: 'List',
                    itemTpl: '{name} [BUTTON]',

                    store: {
                        fields: ['name'],
                        data: [
                            { name: 'one' },
                            { name: 'two' },
                            { name: 'three' }
                        ]
                    },

                    listeners: {
                        itemtap: function(list, index, target, record) {
                            view.push({
                                xtype: 'panel',
                                title: record.get('name'),
                                html: 'This is my pushed view!'
                            })
                        }
                    }
                }
            ]
        });
    }
});

共有2个答案

上官恩
2023-03-14

代替按钮,我们可以在列表的每一行中使用图像,并在监听器中获得点击事件(在我的情况下,我在控制器类中做到了)。我希望以下将帮助你:

包含视图页的列表:

items: [
   {
        xtype: 'list',
        ui: 'normal',
        itemTpl: [

            '<div class="x-list-item speaker">',
                    '<div class="avatar" style="background-image: url(resources/images/contactImages/{item6});"></div>',
                    '<div class="rightarrow" style="background-image: url(resources/images/homeScreenIphone/list_arrow.png);"></div>',
                    '<div class="image_popup_email" style="background-image: url(resources/images/commonImages/mail.png);"></div>',
                    '<div class="image_popup_workphone_icon" style="background-image: url(resources/images/commonImages/workphone_icon.png);"></div>',
                    '<div class="image_popup_phone" style="background-image: url(resources/images/commonImages/phone.png);"></div>',
                    '<h3>{item1}</h3>',
                    '<h4>{item2}</h4>',
            '</div>'
     ],
     store: 'ContactItemListStore'
   }
   ]

在控制器类中:

onContactSelect: function(list, index, element, record, evt){

    // if click on any icon(Cell/Work Phone/Email) in any row of list
    if(evt.getTarget('.image_popup_phone')) {

        var contactNoCell = record.getData().item4;
        window.location.href = "tel:"+contactNoCell;

    }else if(evt.getTarget('.image_popup_workphone_icon')) {

        var contactNoOffice = record.getData().item7;
        window.location.href = "tel:"+contactNoOffice;

    }else if(evt.getTarget('.image_popup_email')) {

        var emailId = record.getData().item5;
        window.location.href = "mailto:"+emailId;

    }else{

    // if click on list row only(not any icon)   
        if (!this.showContactDetail) {
            this.showContactDetail = Ext.create('MyApp.view.phone.MyContactDetail');
        }

        // Bind the record onto the show contact view
        this.showContactDetail.setRecord(record);

        // Push the show contact view into the navigation view
        this.getMain().push(this.showContactDetail);
    }
        //disable selection while select row in list
        list.setDisableSelection(true);
}
班安平
2023-03-14

这不能用Ext完成。列表,你必须使用ComponentView来代替。

它有一些关键概念:Ext.dataview.Component.DataItem,通过Ext.factory()进行自定义配置和转换,有关更多详细信息,请参阅:

http://docs.sencha.com/touch/2-0/#!/guide/dataview

希望能有帮助。

 类似资料:
  • 我正在尝试添加溢出图标(以显示弹出菜单)到列表的每一行。每行左侧有图像(70dp*70dp),右侧有溢出图标图像(27dp*70dp)。 我现在的布局是这样的: 但是这样,中间行的文本会重叠右侧的溢出图标。这是我不想要的。问题是,点击溢出图标被视为点击行,因此弹出菜单永远不会出现。 如何在RelativeLayout中指定将左图像对齐到左侧,右图像对齐到右侧,并将中间的所有可用空间用于textvi

  • 我想将我的添加到列中,这样我就可以在加载更多项目时在这个列表视图下面添加CircularProgressIndex ator。我使用了如何在Flutter中将列表视图添加到列中的建议?因此我制作了结构列- 你能告诉我我做错了什么吗?这个构建了新的小部件,但它构建在另一个列上。也许这是错的?

  • 我正在为一个网格窗格分配几个按钮。每个按钮都有一个数字作为其文本。我创建了一个arrayList numbers并向其添加数字。我使用集合来洗牌数字(我希望每次运行程序时在每个按钮中都有一个随机数)。然后我使用这个ArrayList向每个按钮文本添加一个数字。 我希望每个按钮都有不同的编号。但是,现在1列中的每个按钮都有相同的编号。 任何关于如何修复此问题的建议都将非常感谢(按钮的文本随机分配)。

  • 我有一个遵循特定模式的整数列表,它很复杂,但例如: 我想用9个副本来扩展列表,但添加一个常量值,每次线性扩展。例如,如果 那么第二个扩展将导致: 所以我想我需要一个循环,循环通过并通过

  • 我希望在R中自动化一个过程,这个过程以前是手工完成的,非常耗时。我想从一个数据帧向另一个数据帧中的每个唯一变量添加一系列观察结果。使用数据的示例可能会更好地说明这一点。。。 表1包含了对每种动物的大量观察,这是我想为每种动物添加一组行的表。 表2显示了应应用于每只动物的行。 最后一个表应该如下所示: 有人能给我指出正确的方向吗?优先使用tidyverse超过基本R(但不是必需的:))