【问题标题】:How to create form elements from model or store in Extjs?如何从模型创建表单元素或在 Extjs 中存储?
【发布时间】:2014-07-08 07:33:47
【问题描述】:

是否可以从模型或 extjs 中的存储创建整个表单。我已经定义了模型和商店,但我不想为了创建表单而再次定义所有字段。

那么是否可以只通过模型类或存储来创建表单?

【问题讨论】:

  • 我不知道是否存在这样的东西......但如果没有的话,写一个应该不难。
  • 是的,我知道,但如果我知道怎么写,我不会在 stackoverflow 上提问 :) 你知道怎么写吗?
  • 我相信这是可能的。只需从模型/商店中获取字段,并为每个字段创建一个表单字段,然后将它们添加到表单中。

标签: javascript forms extjs extjs4


【解决方案1】:

这是我根据GridPanel 的列配置呈现表单的操作。也许它可以让你知道从哪里开始。

 renderContactFormFields: function (window) {

    //In my case, the structure is such: Window->FormPanel->BasicForm->FieldSet
    //So I want to add fields within the fieldset...
    var fieldSet = window.down('form').down('fieldset');

    var fieldSetItem;

    //'fieldsToRender' is actually the 'columns' property of a GridPanel
    //that I simply put into a property of the window object to access it later
    for (var i = 0; i < window.fieldsToRender.length; i++) {

        var col = window.fieldsToRender[i];

        fieldSetItem = { name: col.dataIndex, fieldLabel: col.text };
        //A textfield in this case, but you could have rules to change the type of field you want to render...
        fieldSetItem.xtype = 'textfield';
        fieldSet.add(fieldSetItem);
    }

    //finally, load the record within the form...(selectedContact is the record that was selected in the GridPanel...)
    window.down('form').loadRecord(window.selectedContact);
}

所以你可以说它是从模型生成的,它与商店相关联,而商店又与 GridPanel 相关联。

【讨论】:

    猜你喜欢
    • 2015-07-12
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 2010-10-28
    • 1970-01-01
    相关资源
    最近更新 更多