dongsuishou8039 2016-06-29 05:07
浏览 292

在select2.empty()之后,Yii2 Select2不清除所选值

$('#category-id').empty();
for (i = 0; i < response[0].category.length; i++) {
    $('#category-id').append($('<option></option>') //here typo mistake
      .attr('value', response[0].category[i].id)
      .attr('selected', 'selected')
      .text(response[0].category[i].category_name));
}

This is from javascript code _form.php in Transaction View. It is triggered by radiobutton click. Select2 contains income and expense categories. When I selected one income category and clicked expense radio button. The option changed expense categories. But the selected income category still showed. It didn't clear.

<?=
$form->field($model, 'category_id')->widget(Select2::classname(), [
    'data' => Category::getCategoryListByType($model->transaction_type),
    'options' => [
        'id'  => 'category-id',
        'placeholder' => Yii::t('frontend/common', 'Please select one'),
        'allowClear' => true,
    ],
    'pluginOptions' => ['allowClear' => true]
]);
?>

Select2 php code. Please help. Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突