简体   繁体   English

如何在sencha touch中拥有可编辑列表?

[英]how to have editable list in sencha touch?

  • I want to build a todo list. 我想建立一个待办事项清单。 So, Im looking for list which on itemDouble tap will allow me to edit item by allowing textfield to appear. 因此,我正在寻找在item双击上的列表,这将允许我通过允许显示文本字段来编辑项目。 Any ideas ?? 有任何想法吗 ??

Here is an iPhone style editable list 这是iPhone样式的可编辑列表

https://github.com/tmanderson/Sencha-Touch-Edit-List https://github.com/tmanderson/Sencha-Touch-Edit-List

Here is a working Example . 这是一个有效的示例
Encapsulate your data in a div which you want to edit.Give the 'data-name' attribute to that div having same data name. 将数据封装在要编辑的div中 ,将'data-name'属性赋予具有相同数据名称的div Capture the itemdoubletap event and find the actual target. 捕获itemdoubletap事件并找到实际目标。 In this example, as the data was ' title ' so gave the same name to its div's attribute 在此示例中,由于数据为“ title ”,因此为其div的属性指定了相同的名称

Ext.create('Ext.List', {
                fullscreen: true,
                itemTpl: '<div data-name="title">{title}</div>',
                data: [
                    { title: 'Item 1' },
                    { title: 'Item 2' },
                    { title: 'Item 3' },
                    { title: 'Item 4' }
                ],
                listeners: {
                    itemdoubletap: function (list, index, target, record, e, eOpts) {
                        var actualTarget = e.getTarget('div');
                        if (actualTarget.dataset.name == 'title') {
                            actualTarget.innerHTML = '';
                            var textfield = document.createElement("INPUT");
                            textfield.setAttribute("type", "text");
                            textfield.style.width = '100%',
                            textfield.record = record;
                            textfield.value = record.data[actualTarget.dataset.name];
                            textfield.onblur = function () {
                                if (record.data[actualTarget.dataset.name] != this.value) {
                                    record.data[actualTarget.dataset.name] = this.value;
                                }
                                this.parentNode.innerHTML = this.value;
                            }
                            actualTarget.appendChild(textfield);
                            textfield.focus();
                        }
                    }
                }
            }

Just create a list, add a itemdoubletap listener to it, and on that event, create a floating panel with textarea and docked toolbar button inside. 只需创建一个列表,向其中添加一个itemdoubletap侦听器,然后在该事件上创建一个带有textarea和固定工具栏按钮的浮动面板。 Check Sencha Touch examples for reference. 查看Sencha Touch示例以供参考。

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

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