关于 sencha touch:ExtJS、SenchaTouch – FormPanel 无法从商店加载值? | 珊瑚贝

ExtJS, SenchaTouch – FormPanel can’t load values from a store?


如何将值从商店加载到表单面板中?我在这里构建了一个完整的示例。

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

型号:

1
2
3
4
5
6
7
8
9
Ext.ns(‘app’, ‘app.defaults’);
        Ext.regModel(‘MyModel’, {
            fields: [
                {name: ‘var1’, type: ‘integer’}
            ]
        });
        app.defaults.vars = {
            var1: 5
        };

店铺:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 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
                });

形式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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-page live 示例的源代码中。


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

1
2
3
  myForm.getForm().loadRecord(Ext.ModelManager.create({
                        ‘var1’:5
                    }, ‘MyModel’));

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

  • .load 或 .loadRecord 工作,只要您传入记录而不是存储。我将修复添加到您的答案中。


来源:https://www.codenong.com/7459361/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9528.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?