【问题标题】:init select2 Yii 2.0: yii2-widgets初始化 select2 Yii 2.0: yii2-widgets
【发布时间】:2014-09-10 21:51:56
【问题描述】:

我有这个代码

echo Select2::widget([
    'model' => implode(', ', ["ROME","NY"]),
    'name' => 'city',
    'options' => [
        'id'=>'city',
        'placeholder' => 'select a city ...',
        'class'=>'form-control'
     ],
     'pluginOptions' => [
         'tags' => $city,
         'maximumInputLength' => 4,
     ],
 ]);

我的 js 文件

 $('#city').on('change',function(x){
    $.ajax({
        url: '?r=markermap/setmarkerajax',
        type: 'POST',
        data: {'city':x.val},
        success: function(res){
            setMarkers(res);
        }
    });
});

当我选择一个城市时插件工作。进入控制器,我存储到会话值中,并希望在重新加载或返回页面时再次设置旧值。 有了这个插件怎么办? 进入页面我读到支持 $model ,但我有会话而不是模型对象。

【问题讨论】:

    标签: php jquery-select2 yii-extensions yii2


    【解决方案1】:
    <?php
    
    $data = ["red", "green", "white", "black", "purple", "cyan"];
    // without model
    echo Select2::widget([
      'name' => 'category',
      'value' => "green,red", // value to initialize
    
      'options'=> [],
      'pluginOptions' => [
        'tags' => $data,
        'maximumInputLength' => 4,
      ],
    
    ]);
    
    ?>
    

    【讨论】:

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