简体   繁体   English

sencha touch:: 如何创建 hbox-items 列表

[英]sencha touch :: how to create list of hbox-items

i want to generate a list of data out of a store.我想从商店中生成数据列表。 each data item holds a title and a boolean.每个数据项都有一个标题和一个 boolean。 now i want to have a list of the items, each holding the title and a togglefield (showing the boolean) on the right of the title.现在我想要一个项目列表,每个项目都包含标题和标题右侧的切换字段(显示布尔值)。

how could I do that?我怎么能那样做?

thnx!谢谢!

From the Sencha Touch documentation, a List is "a mechanism for displaying data using a list layout template", ie html template.从 Sencha Touch 文档中,List 是“一种使用列表布局模板显示数据的机制”,即 html 模板。 If you want a 'list' of components, you'll have to make your own extension of DataView (I think).如果你想要一个组件的“列表”,你必须自己扩展 DataView (我认为)。

A workaround could be to put an html checkbox inside your itemTpl.一种解决方法是在您的 itemTpl 中放置一个 html 复选框。 Something like (warning - not tested):类似的东西(警告 - 未经测试):

itemTpl: '<p>{title}: <input type="checkbox" name="BoolCheckbox" class="boolcheckbox"'
    + "{[(values.bool? 'checked="checked"' : '')]}"
    + '></input></p>'

To run your own code in the XTemplate, you bracket it with {[]}.要在 XTemplate 中运行您自己的代码,请将其括在 {[]} 中。 When in this scope, you have access to a variable 'values', which contains the data for the record.在此 scope 中,您可以访问包含记录数据的变量“值”。

To detect events, you'd add a listener to the list:要检测事件,您需要在列表中添加一个侦听器:

itemtap: function (dataView, index, item, e) {
    if (e.getTarget().getClass().toString() == "boolcheckbox") {
        // do something
    }
}

Some resources on templates:关于模板的一些资源:

http://dev.sencha.com/deploy/touch/docs/ http://dev.sencha.com/deploy/touch/docs/

http://www.sencha.com/learn/xtemplates-part-i/ http://www.sencha.com/learn/xtemplates-part-i/

http://www.sencha.com/learn/xtemplates-part-ii/ http://www.sencha.com/learn/xtemplates-part-ii/

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

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