在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配置选项
任何帮助形式Ext master ???
答案 0 :(得分: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类。我希望同样的东西也适用于收音机。
答案 1 :(得分:0)
对于Sencha Touch,图标以字体存储:Pictos。这是角色map 例如,这是我创建复选框按钮的方式(注意:链接缺少回调函数)。只需更改字体颜色即可显示是否已选中。
在Css中:
a {
text-decoration: none;
}
.icon {
font-family: "Pictos";
}
在HTML中:
<span>
Item #1
<a href="#">
<span class="icon">3</span>
</a>
</span>