简体   繁体   English

Sencha Touch 2在字段集中添加和删除文本字段

[英]Sencha Touch 2 Add and Remove textfield inside fieldset

i have strange issue with removing item from fieldset. 我从字段集中删除项目有一个奇怪的问题。 my app success adding new textfield fieldset item, buth when i do remove() my app screen got stuck without any error on my google chrome. 我的应用程序成功添加了新的textfield fieldset项,但是当我执行remove()时,我的应用程序屏幕被卡住了,而Google chrome上没有任何错误。 here my source view js 这是我的源代码视图js

Ext.define('qms.view.QC23', {
    extend: 'Ext.form.FormPanel',
    alias: 'widget.QC23View',
    id: 'QC23View',
    requires: ['Ext.form.FieldSet', 'Ext.Label'],
    config: {
        items: [
{
                        xtype: 'fieldset',
                        //defaults: { labelAlign: 'top' },
                        Id:'defectAdd',
                        layout:{

                        },
                        items: [
                            {
                                xtype: 'button',
                                text: 'New Defect',
                                id: 'DefectQC23Button',
                                ui: 'action'
                            },
                            {
                                xtype: 'button',
                                text: 'Remove Defect',
                                id: 'RemoveQC23Button',
                                ui: 'action'
                            }
                        ]
                    }
]
}

and my controler 和我的控制者

Ext.define('qms.controller.QC23con', {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            addDefectButton:'#DefectQC23Button',
            rmDefectButton:'#RemoveQC23Button'

        },
        control: {
            addDefectButton:{
                tap: 'addDefect'
            },
            rmDefectButton:{
                tap: 'removeDefect'
            },
        }
    },
    addDefect: function(button){        
        button.up('fieldset').add({
        xtype: 'textfield',
        name: 'MyField-' + button.up('fieldset').length
        });
        //Ext.getCmp('defectAdd').doLayout();
    },
    removeDefect: function(button){
        button.up('fieldset').remove(button.up('fieldset').items.items[0]);
    }

the function for adding item work fine, but when i remove the item my screen stuck. 添加项目的功能工作正常,但是当我删除项目时,我的屏幕卡住了。 i am using google chrome for testing. 我正在使用谷歌浏览器进行测试。

please give me solution for this issue. 请给我解决这个问题的方法。 thanks. 谢谢。

I noticed you are not checking for the xtype before removing an item from the fieldset. 我注意到您在从字段集中删除项目之前没有检查xtype。 The code might be removing the button itself in which case it might cause your screen to freeze. 代码可能会删除按钮本身,在这种情况下,它可能会导致屏幕冻结。 I created a simple sencha fiddle https://fiddle.sencha.com/#fiddle/4tf that does what you are trying to accomplish. 我创建了一个简单的sencha小提琴https://fiddle.sencha.com/#fiddle/4tf ,它可以完成您要完成的任务。

replace the removeDefect function with this: 替换为removeDefect函数:

var lastItem = button.up('fieldset').items.items.length-1;
if(button.up('fieldset').items.items[lastItem].xtype ==='textfield')
    button.up('fieldset').remove(button.up('fieldset').items.items[lastItem]);

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

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