4

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

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

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

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 配置选项

任何帮助形式的分机大师???

4

2 回答 2

5

我想通了,我需要使用一个模板,我使用 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 类。我希望同样的事情也适用于广播。

于 2011-01-31T18:49:49.567 回答
0

对于 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>
于 2014-03-10T19:21:35.647 回答