繁体   English   中英

Sencha Touch ExtJS添加复选框列表

[英]Sencha Touch ExtJS adding checkbox to list

在Sencha Touch 1.0中进行开发。 我正在使用Ext.List来呈现列表,但我还希望每个列表项的开头都以复选框开头。 我还想根据数组项值更改其状态,该数组是给配置选项的数组。 有没有办法将一个简单的Ext.form.Checkbox添加到Ext.List。

如果我改为在<itemTpl>配置选项中使用<input type="checkbox".../> ,那么它在显示中看起来很难看,其次我不知道如何在复选框上监听事件

这是你的眼睛糖果的代码:

Ext.regModel('Todos', {
    fields: ['title', 'completed_at']
});

var groupingBase = {
    itemTpl: '<div class="contact2"><strong>{title}</strong></div>',
    selModel: {
        mode: 'SINGLE',
        allowDeselect: true
    },
    // grouped: true,
    indexBar: true,

    onItemDisclosure: {
        scope: 'test',
        handler: function (record, btn, index) {
            alert('Disclose more info for ' + record.get('title'));
        }
    },

    store: new Ext.data.Store({
        model: 'Todos',
        sorters: 'title',

        getGroupString: function (record) {
            return record.get('title')[0];
        },

        data: [todos] //todos array is prev populated with required items' properties 
    })
};

myList = new Ext.List(Ext.apply(groupingBase, {
    fullscreen: true
}));
//List ends

tasksFormBase = {
    title: 'Tasks',
    iconCls: 'favorites',
    cls: 'card2',
    badgeText: '4',
    layout: 'fit',
    items: [
    myList, {
        xtype: 'checkboxfield',
        name: 'cool',
        label: 'Cool'
    }],
    dockedItems: [todosNavigationBar]
};  

//然后将tasksFormBase添加到Ext.TabPanel配置选项中

任何帮助形式Ext master ???

我想,我需要使用一个模板,我使用了List控件的itemTpl属性,其中tpl看起来像:

<textarea id="todos-template" class="x-hidden-display">
            <div id="todo_item_{todo_id}" class="todo_list">
                <input type="checkbox" id="todo_check_{todo_id}" class="todo_checkbox unchecked"/>         <strong>{title}</strong>
            </div>
</textarea>

并添加了以下监听器:

itemtap: function(dataview, index, item, event) {
var todo = dataview.getStore().getAt(index).data;
if (eve.getTarget('input#todo_check_'+todo.todo_id)) {
                    Ext.get(item).addCls('selected');
                    ele = Ext.get('todo_check_'+todo.todo_id);

                    //reverse condition as the event is fired before the state is set
                    if(!ele.getAttribute('checked')) {
                        todo.completed_at = Api.formatDate(new Date());
                        ele.replaceCls('unchecked', 'checked');
                    } else {
                        ele.replaceCls('checked', 'unchecked');
                        todo.completed_at = null;
                    }
}

因此,在点击列表项时,我会检测是否点击了该复选框并相应地更改了相关的div CSS类。 我希望同样的东西也适用于收音机。

对于Sencha Touch,图标以字体存储:Pictos。 这是字符映射 。例如,这是我创建复选框按钮的方式(注意:链接缺少回调函数)。 只需更改字体颜色即可显示是否已选中。

在Css中:

a {
text-decoration: none;
}
.icon {
 font-family: "Pictos"; 
}

在HTML中:

<span>
  Item #1 
  <a href="#">
  <span class="icon">3</span>
  </a>
 </span>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM