如何在magneto 2中的自定义模块中添加多选项?

时间:2016-05-25 14:52:18

标签: magento-2.0

我需要添加多选下拉列表。 我试过下面的代码。但它没有绑定dropdown.how中的值来做到这一点吗?

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

2 个答案:

答案 0 :(得分:0)

$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数组。

答案 1 :(得分:0)

@KapilSinghathia在最后的某个时刻你有$form->setValues($model->getData());

  

$形式 - > setValues方法($模型 - >的getData());       $ form-> addValues(array('select_product'=> $ options);       $形式 - > addValues($模型 - >的getData());

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

相关问题