【问题标题】:Select2 removes data on edit event in formSelect2 删除表单中编辑事件的数据
【发布时间】:2018-08-05 04:59:14
【问题描述】:

我正在尝试在选择 2 框中获取所选数据,然后允许用户从下拉列表中选择其他条目。但是,当用户单击 EDIT 时,表单会加载所有数据,但在 select2 下拉数据中会显示一秒钟,然后它会刷新/隐藏。

视频: https://drive.google.com/file/d/1B10cFedD7h9o1MybhLlmlyq_voL7T6SP/view

表单 JS:

// Init the Cx Form
    $cxRecordEditForm.cxForm({
        loadDataUrl: '<?php echo $this->CxHelper->Route('eb-admin-get-evaluation-cause-by-id')?>',
        loadData: {listSymptoms: true, listRemedies: true},
        loadSuccess: function(formData){
            if(formData){
                // Get Linked Symptoms on EDIT
                var symptomsListArray = formData.symptoms_list;
                if(symptomsListArray){
                    symptomsListArray.forEach(function(entry) {
                        // create the option and append to Select2
                        var option = new Option(entry.text, entry.id, true, true);
                        $('#symptoms_list').append(option).trigger('change');
                    });
                }

                // Get Linked Remedies on EDIT
                var remediesListArray = formData.remedies_list;
                if(remediesListArray){
                    remediesListArray.forEach(function(entry) {
                        // create the option and append to Select2
                        var option = new Option(entry.text, entry.id, true, true);
                        $('#remedies_list').append(option).trigger('change');
                    });
                }
            }
        },

查看:

<section class="col col-6">
                                                <label class="label">{{EbEvaluationCauseForm.getLabel("symptoms_list")}}</label>
                                                <label class="input">
                                                    {{ EbEvaluationCauseForm.render("symptoms_list", ["class": "select2"]) }}
                                                </label>
                                            </section>

                                            <section class="col col-6">
                                                <label class="label">{{EbEvaluationCauseForm.getLabel("remedies_list")}}</label>
                                                <label class="input">
                                                    {{ EbEvaluationCauseForm.render("remedies_list", ["class": "select2"]) }}
                                                </label>
                                            </section>

表格:

public function initialize() {

        // Create form fields
        $this->add($this->createHiddenField('id'));
        $this->add($this->createTextField('title', 'Title', false));
        $this->add($this->createTextField('description', 'Explanation', false));
        $this->add($this->createSelect2Field('symptoms_list', 'Symptoms', 'Select Symptom','symptoms',false, true, true));
        $this->add($this->createSelect2Field('remedies_list', 'Remedies', 'Select Remedy','remedies',false, true, true));
    }

编辑点击时返回的 JSON 是:

{"data":{"id":53,"title":"Well Test","description":"Well Test 解释","is_active":1,"order_by":null,"date_created":"0000-00-00 00:00:00","date_updated":"0000-00-00 00:00:00","症状":[{"id":18,"text":"小牛 温柔"}],"symptoms_list":[{"id":18,"text":"小牛 温柔"}],"补救措施":[{"id":4,"text":"肾上腺 套件"},{"id":4,"text":"肾上腺 Kit"}],"remedies_list":[{"id":4,"text":"肾上腺 套件"},{"id":4,"text":"肾上腺套件"}]}}

谢谢

【问题讨论】:

    标签: javascript json jquery-select2 phalcon


    【解决方案1】:

    控制器好像在重新生成视图,你试过了吗:

    $this->view->disable();
    

    有吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 2017-06-28
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 2021-04-08
      相关资源
      最近更新 更多