【问题标题】:Displaying buttons in a Dataview in Sencha 2在 Sencha 2 的数据视图中显示按钮
【发布时间】:2015-07-02 23:02:41
【问题描述】:

我正在尝试创建一个视图,该视图本质上是一个列表,其中每一行都有文本和 2 个右对齐的按钮。按钮的文本将始终相同 - 只有行的文本需要从存储中获取。

我看到了这个question,但无法让提议的solution 工作。我的商店里肯定有记录,但数据视图没有显示。

我的代码的简化版本:

我的主要观点:

Ext.define('MyApp.view.Main', {
    extend: 'Ext.Container',
    ...
    config: {
        layout: {
            type: 'vbox',
            pack: 'center',
            align: 'middle'
        },
        items: [
           ...
           {xtype: 'mylist'}
           ...
        ]
        ...
    }
    ...
});

数据视图:

Ext.define('MyApp.view.MyList', {
    extend: 'Ext.dataview.DataView',
    alias: 'widget.mylist',
    requires: ...,
    config: {
         useComponents: true,
         store: 'my-store',
         defaultType: 'listitem'
     }
});

数据项:

Ext.define('MyApp.view.ListItem', {
    extend: 'Ext.dataview.component.DataItem',
    alias: 'widget.listitem',
    config: {
        layout: ...
        items: [{
            xtype: 'component',
            itemId: 'description',
            html: '',
            flex: 2
        },
        {
            xtype: 'button',
            text: 'a button',
            itemId: ...,
            flex: ...
         },
         {
             ... another button
         }]
     },
     updateRecord: function(record) {
         ...
         this.down('#description').setHtml(record.get('description'));
         // record.get('description') does give me an undefined value
     }
});

假设我的商店和模型设置正确,问题可能是什么?

或者,也许我应该只使用标准列表,但将宽度设置为

编辑:
最终使用了 dataMap 方法。 我的 DataItem 现在看起来像:

config: {
    layout: {
        type: 'hbox',
        align: 'center'
    },
    dataMap: {
        getDescription: {
            setHtml: 'description'
        }
    },
    description: {
        flex: 1
    }
},
applyDescription: function(config) {
    return Ext.factory(config, Ext.Component, this.getDescription());
},
updateDescription...

基本喜欢this

我现在看到了标签,但我不知道如何在其中获取按钮。由于我不想将其链接到商店,因此我不想将其放在dataMap 中。我尝试将其放入items,但无济于事。

编辑 2:
好吧,让按钮显示比我想象的要容易。这只是我对标签所做的重复,但没有将其包含在 dataMap 中 - yesButton: {...}, applyYesButton: f(){...}, updateYesButton: f(){...}...

我需要解决的最后一个问题是,如何唯一标识它们。我想要按钮上的侦听器,但以某种方式将记录传递到处理程序中。

【问题讨论】:

    标签: sencha-touch sencha-touch-2 senchatouch-2.4


    【解决方案1】:

    我在数据视图中获取按钮而不将其链接到商店的解决方案。实际上,不出所料,它类似于 blog post

    查看 - ListItem.js

    ...
    config: {
        layout: {
           type: 'hbox',
           align: 'center'
        },
        dataMap: {
            getDescription: {
                setHtml: 'description'
            }
        },
        description: {
            cls: ...,
            flex: 4
        },
        myButton: {
            cls: ...,
            text: 'Button!',
            flex: 1
        }
    },
    applyDescription, updateDescription (same as in the question),
    applyMyButton: function(config) {
        return Ext.factory(config, Ext.Button, this.getMyButton());
    },
    updateMyButton: function(newButton, oldButton) {
        ... same logic as the other update method
    }
    

    在我的数据视图中:

    ...
    config: {
        itemId: ...,
        store: ...,
        useComponents: true,
        defaultType: 'listitem',
        width: '100%',
        flex: 1,
        listeners: {
            itemtap: function(dataview, index, element, evt) {
                var store = dataview.getStore();
                var record = store.getAt(index);
                ...
            }
        }
    }
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多