簡體   English   中英

ExtJS 6:使用Ext.data.Model和loadRecord方法使用復選框填充表單

[英]ExtJS 6: Populate a form with checkboxes using Ext.data.Model and loadRecord method

我正在嘗試使用JavaScript對象和Ext.data.Model用復選框填充表單。 使用textField形式,以下代碼可以正常工作:

// text is an array with text values
var currentForm = {
                  "name_value1": text[0],
                  "name_value2": text[1],
               };


Ext.define('CurrentFormModel', {
    extend: 'Ext.data.Model',
    fields: ['name_value1', 
             'name_value2', 
            ]
    });


var Get_textFieldForm = textFieldForm.getForm();
Get_textFieldForm.loadRecord(new CurrentFormModel(currentForm));

如何使用復選框形式成功完成該任務? 我嘗試了以下方法:

// text[2][i] is an array with the checked values
var checkFormObj = {
       "checkboxGroupName": [text[2][0], text[2][1]]
       }

 Ext.define('CheckboxModel', {
                 extend: 'Ext.data.Model',
                 fields: [{name: 'checkboxGroupName', type: 'boolean'}]
               });
 var Get_CheckboxForm = CheckboxForm_name.getForm();
 Get_CheckboxForm.loadRecord(new CheckboxModel(checkFormObj));

我的復選框形式:

CheckboxForm_name = Ext.create('Ext.form.Panel', {
        title: 'Checkbox form',
        collapsible: true,
        collapsed: true,
        items: [{
               xtype: 'checkboxfield',
               name: 'checkboxGroupName',
               boxLabel: 'Checkbox1',
               inputValue: 'checkbox_1'
               }, {
               xtype: 'checkboxfield',
               name: 'checkboxGroupName',
               boxLabel: 'Checkbox2',
               inputValue: 'checkbox_2'
               }]
       });

但是什么也沒發生。 有任何想法嗎 ?

我設法解決了這個問題。 無需使用字段定義對象,也無需擴展Ext.data.Model類即可包括這些字段。 下面的代碼填充復選框表單。

var CheckboxModel = new Ext.data.Model({
                <name>: [<inputValue>, // the input values of checkboxes
                         <inputValue>
                        ]
              });

var Get_CheckboxForm = CheckboxForm_name.getForm();
Get_CheckboxForm.loadRecord(CheckboxModel);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM