json - Extjs 4 : Render store data into Ext. form.Panel不使用MVC框架

标签 json forms extjs extjs4 store

在下面您将找到一个具有两个字段的 Ext.form.Panel。我在模型中选择了两个有数据的随机字段。它们没有以表单形式呈现。请注意,在此代码中我没有在 Extjs 框架中使用 MVC。 如何渲染这些字段?我已经粘贴了 store.data.toSource() 的相关输出,以表明我的商店中确实有数据,并且只有一条记录。要以稍大的分辨率查看图像,请右键单击它并在另一个选项卡中查看。

NOTE: .toSource() only works in Mozilla Firefox

我尝试在创建表单后执行此操作,但没有成功:

taskForm.getForm().loadRecord(store.getAt(0));

代码:

    var taskForm = Ext.create('Ext.form.Panel', {
        title: 'Task',
        id: 'form1',
        width: 600,
        height: 200,
        bodyPadding: 10,
        renderTo: 'TaskEditForm',
        store: store,
        style: {
            'position': 'fixed',
            'top': '100px',
            'left': '10px'
        },

        items: [{
            xtype: 'label',
            labelAlign: 'right',
            name: 'project_id',
            fieldLabel: 'Project ID',
            width: 100
        }, {
            xtype: 'label',
            labelAlign: 'right',
            name: 'user_responsible',
            fieldLabel: 'User',
            width: 100
        }],

        buttons: [{
            text: 'Save Task Detail',
            handler: function (btn) {

                alert(store.data.toSource());

            }

        }]
    });

enter image description here

========

编辑:@Evan

此代码给出以下错误:

taskForm.getForm().loadRecord(store.getAt(0));

错误:

TypeError: record is undefined

...

return this.setValues(record.data);  // ext-all-debug.js (line 109529)

109529行:

loadRecord: function(record) {
  this._record = record;
  return this.setValues(record.data);
}, 

最佳答案

你读过文档了吗? store.data 是一个包含一堆记录的 MixedCollectionload 方法的文档说:

A class which handles loading of data from a server into the Fields of an Ext.form.Basic.

你不能只输入随机参数并期望东西能够工作。

您可能想要的是:

form.getForm().loadRecord(store.getAt(0));//将第一条商店记录加载到表单中

关于json - Extjs 4 : Render store data into Ext. form.Panel不使用MVC框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16928617/

相关文章:

javascript - JSONP使用JQuery从HTTPS协议(protocol)中获取JSON

java - 无法使用 START_ARRAY token 反序列化任务实例

extjs - 滑动/动画 Extjs 窗口

asp.net - 显示从 json post 调用返回的文本

java - Jersey 自定义 JSON 响应

javascript - 不断出现错误 : "Failed with: Uncaught SyntaxError: Unexpected token T in <unknown file>:1" (PARSE CLOUD CODE)

ruby-on-rails - content_tag 不适用于 f.submit on rails 5.1

python - 在 Python Pyramid 路由配置中使用查询字符串

javascript - 动态生成Javascript提交按钮

extjs - 如何将 Sencha cmd 生成的 'overrides' 文件夹用于 Ext JS 4 项目