【问题标题】:how to add multi select option in custom module in magneto 2?如何在 magento 2 的自定义模块中添加多选选项?
【发布时间】:2016-05-25 14:52:18
【问题描述】:

我需要添加多选下拉菜单。 我在下面的代码中尝试了这个。但它没有绑定dropdown中的值,怎么做?

$fieldset->addField(
            'select_product',
            'multiselect',
            [
                'label' => __('Select Product'),
                'title' => __('Select Product'),
                'name' => 'select_product',
                'required' => true,
                'options' => $this->_status->getOptionArray(),
                'disabled' => $isElementDisabled
            ]
        );

【问题讨论】:

    标签: magento-2.0


    【解决方案1】:
    $options[1]['value'] = 'value here'; 
    
    $options[1]['label'] = 'this is value';
    
            $fieldset->addField(
                    'allowed_timeslots', 'multiselect', array(
                'name' => 'allowed_timeslots[]',
                'label' => __('Allowed Timeslot'),
                'title' => __('Alloewd Timeslot'),
                'values' => $options,
                'required' => true,
                'disabled' => false
                    )
            );
    

    请以上述格式传递 $options 数组。

    【讨论】:

      【解决方案2】:

      @KapilSinghathia 最后你有$form->setValues($model->getData());

      $form->setValues($model->getData()); $form->addValues(array('select_product'=> $options); $form->addValues($model->getData());

      它对我有用,希望对你有帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多