【问题标题】:ExtJS, SenchaTouch - FormPanel can't load values from a store?ExtJS、SenchaTouch - FormPanel 无法从商店加载值?
【发布时间】:2011-09-19 03:37:13
【问题描述】:

如何将值从商店加载到表单面板中?我已经建立了一个entire broken example here

我不确定为什么我的表单域没有加载。

型号:

Ext.ns('app', 'app.defaults');
        Ext.regModel('MyModel', {
            fields: [
                {name: 'var1', type: 'integer'}
            ]
        });
        app.defaults.vars = {
            var1: 5
        };

商店:

 var myStore = new Ext.data.Store({
                    model: 'MyModel',
                    proxy: {
                        type: 'localstorage',
                        id: 'model-proxy'
                    },
                    listeners: {
                        load: function(store, records, successful) {
                            if (this.getCount() > 1) {
                                alert('Error: More than one record is impossible.');
                                this.proxy.clear();
                            }
                            if (this.getCount() == 0) {
                                alert( "Count 0, loading defaults");
                                this.add(app.defaults.vars);
                                this.sync();
                            }

                            console.log("Attempting to load store");
                            myForm.load(this);
                        }
                    },
                    autoLoad: true,
                    autoSave: true
                });

形式:

var myForm = new Ext.form.FormPanel({
                    id: 'my-form',
                    scroll: 'vertical',
                    items: [
                        {
                            xtype: 'fieldset',
                            defaults: {
                                labelWidth: '35%'
                            },
                            items: [
                                {
                                    xtype: 'numberfield',
                                    id: 'var1',
                                    name: 'var1',
                                label: 'Var1',
                                placeHolder: '100',
                                useClearIcon: true
                            }
                        ]
                    }
                ]
            });

【问题讨论】:

  • @Gregory Nozik:更新了模型。它位于 1 页实时示例的源代码中。

标签: sencha-touch local-storage extjs formpanel


【解决方案1】:

我找到了其他方式将表单与数据连接起来 加载表单后插入以下代码

  myForm.getForm().loadRecord(Ext.ModelManager.create({
                        'var1':5
                    }, 'MyModel'));

那么,加载记录而不是存储。加载 records[0] 而不是 this

【讨论】:

  • .load.loadRecord 工作,只要您传入记录而不是存储。我已将修复添加到您的答案中。
猜你喜欢
  • 1970-01-01
  • 2015-05-26
  • 2013-05-16
  • 1970-01-01
  • 2013-03-17
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多