Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 为什么要炸掉这扇窗户_Forms_Extjs - Fatal编程技术网

Forms 为什么要炸掉这扇窗户

Forms 为什么要炸掉这扇窗户,forms,extjs,Forms,Extjs,我有一个加载了用户数据的表单(来自Json存储)。当我第一次单击时,表单显示良好。但是,第二次崩溃: 萤火虫说: 当我在此表单之后显示其他表单时,也会崩溃。 有什么想法吗 编辑以获取更多信息: 要加载表单的代码为: cargarFormularioEdicion: function(idPaciente){ var store = Ext.create('cp.store.form.Paciente',{}); store.load({params:{idUs

我有一个加载了用户数据的表单(来自Json存储)。当我第一次单击时,表单显示良好。但是,第二次崩溃:

萤火虫说:

当我在此表单之后显示其他表单时,也会崩溃。 有什么想法吗

编辑以获取更多信息: 要加载表单的代码为:

cargarFormularioEdicion: function(idPaciente){
        var store = Ext.create('cp.store.form.Paciente',{});
        store.load({params:{idUsuario: idPaciente}});
        var form = Ext.create('cp.view.form.EditPaciente',{
            action: 'bin/paciente/modificar.php'
        });
        // Ver la forma de pasar este listener al controller
        form.on('afterrender',function(form,idPaciente){
           form.getForm().loadRecord(store.first());
           form.getForm().findField('idUsuario').setValue(idPaciente);
        });
        var win = Ext.create('cp.view.ui.DecoratorForm',{
            aTitle: 'Editar paciente',
            aForm: form
        });
        win.show();
    }
假设解决方案: 使用async=false加载存储

        var store = Ext.create('cp.store.form.Paciente',{});
        Ext.apply(Ext.data.Connection.prototype, {
                async: false
        });
        store.load({params:{idUsuario: idPaciente}});
var store = Ext.create('cp.store.form.Paciente',{});
Ext.apply(Ext.data.Connection.prototype, {
        async: false
});
store.load({params:{idUsuario: idPaciente}});

假设的解决方案:使用async=false加载存储

        var store = Ext.create('cp.store.form.Paciente',{});
        Ext.apply(Ext.data.Connection.prototype, {
                async: false
        });
        store.load({params:{idUsuario: idPaciente}});
var store = Ext.create('cp.store.form.Paciente',{});
Ext.apply(Ext.data.Connection.prototype, {
        async: false
});
store.load({params:{idUsuario: idPaciente}});

您的代码不保证在
form.getForm().loadRecord(store.first())时加载存储被调用。因为它可能不是,所以在处理
loadRecord
过程中的某个地方,期望尝试访问未定义的变量(如错误消息所示),从而导致javascript执行崩溃。这使得表单组件的内部状态被破坏,因此从那里开始,一切都是丑陋的

通过同步加载商店,您已经发现了这一点,但这确实是您应该避免的。它通过阻塞线程来浪费处理时间,并且可能会将应用程序冻结几秒钟

处理异步事件的正确方法是向它们传递一个函数,当异步事件发生时,它们将调用该函数。因此命名为回调函数(和笑话“好莱坞原则”)。这是高效和安全的

由于回调函数可以通过多种方式传递,因此需要参考文档。以您的代码为例,查看文档以了解更多信息。下面是如何优雅地修复代码:

cargarFormularioEdicion: function(idPaciente){
    var store = Ext.create('cp.store.form.Paciente');

    store.load({
        params:{idUsuario: idPaciente}

        // here's how to pass a callback to Store#load
        // notice you get access to some useful parameters as well!
        ,callback: function(records, operation, success) {
            if (!success) {
                // the execution will continue from here when the store is loaded

                var form = Ext.create('cp.view.form.EditPaciente',{
                    action: 'bin/paciente/modificar.php'
                });
                // Ver la forma de pasar este listener al controller
                form.on('afterrender',function(form,idPaciente){
                   form.getForm().loadRecord(store.first());
                   form.getForm().findField('idUsuario').setValue(idPaciente);
                });
                var win = Ext.create('cp.view.ui.DecoratorForm',{
                    aTitle: 'Editar paciente',
                    aForm: form
                });
                win.show();
            } else {
                // you need to handle that case
            }
        }
    });
}

错误说明
记录未定义
。是吗?@Madbreaks我在问题中添加了加载代码。我想这就解决了。配置加载存储async=false.Unrelated,但我怀疑您是否必须等待表单呈现才能调用
loadRecord
findField
(或在find字段上调用
setValue
)。这些方法适用于组件抽象模型,而不是DOM本身。