Select2会以格式

时间:2018-08-05 04:59:14

标签: javascript json jquery-select2 phalcon

我正在尝试在“选择2”框中获取所选数据,然后允许用户从下拉列表中选择其他条目。但是,当用户单击“编辑”时,该窗体将加载所有数据,但在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,”文本“:”小腿   柔情“}],”症状列表“:[{” id“:18,”文字“:”小腿   压痛“}],”补救措施“:[{” id“:4,”文本“:”肾上腺   工具包“},{” id“:4,” text“:”肾上腺   Kit“}],” remedies_list“:[{” id“:4,” text“:”肾上腺   套件“},{” id“:4,”文字“:”肾上腺套件“}]}}

谢谢

1 个答案:

答案 0 :(得分:0)

您是否尝试过,似乎控制器正在重新生成视图?

$this->view->disable();

有吗?