【问题标题】:How to add a CSS class to a dataview element onItemTap event in Sencha Touch?如何将 CSS 类添加到 Sencha Touch 中的 dataview 元素 onItemTap 事件?
【发布时间】:2014-07-29 16:09:17
【问题描述】:

我通过使用 for 循环从 JSON 存储中的数组加载数据来创建数据视图列表。因此,CSS 应用于整个数据视图而不是单个元素。

{
        xtype: 'dataview',
        store: 'AnswerStore',
        flex:8,
        height: 600,
        width: '100%',
        style: 'background-color:gray; padding: 10px;',
        itemTpl: [
        '<tpl for=".">',
            '<tpl for="questionAnswers">',
                '<div>{answer}</div>',
            '</tpl>',
            '</tpl>'
        ],
        onItemTap: function (container, target, index, e) {
            var me = this;
            this.setStyle('color:red');
        }

【问题讨论】:

    标签: extjs sencha-touch dataview


    【解决方案1】:

    在您的 onItemTap 中,新样式应应用于 target 对象(即被点击的项目)。另外 -非常重要- onItemTap 的参数需要重新排序为function(container, index, target, e)

    这是整个onItemTap 函数:

    onItemTap: function(container, index, target) {
        target.setStyle({color: 'red'});
    }  
    

    如果你想看到它的实际效果,我有一个工作小提琴:https://fiddle.sencha.com/#fiddle/8g1

    【讨论】:

      【解决方案2】:

      要获得此输出,请创建 css 类并将其作为 pressCls 配置列出。 如果您想覆盖选定的样式,则将其作为 selectedCls 配置列出。

      【讨论】:

        猜你喜欢
        • 2013-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多