Kartik的星级评级:如何设置插件?

时间:2018-01-10 14:31:57

标签: yii2

我做了下一个:

  1. 在我的Yii2应用程序中安装了Kartik的星级小部件
  2. 'pluginOptions'的混乱设置
  3. 直到现在一切正常,但我现在不知道如何使用 'pluginevents'。首先,我想做一个简单的警报('确定') 对于“rating-chage”活动,但没有成功:
  4. 代码:

      echo StarRating::widget([
           'name' => $post->post_rate,
           'value' => isset($post->post_rate) ? $post->post_rate : 0,
           'pluginOptions' => [
                         'size'=>'xs',
                         'filledStar' => '★',
                         'emptyStar' => '☆', 
                         'showCaption' => false,
                         ],
           'pluginEvents' => [
                        "rating.change" => "function() \n\t{\n\t alert('ok'); \n\t}\n\t"
                         ],
    

    问题: 为什么在我躲上一颗星之后不再保持警觉?

    Image from view:

1 个答案:

答案 0 :(得分:0)

当您尝试首次使用此插件时,如果您查看rating:change documentation,则应该rating.change而不是javascript,这是常见错误将其更改为以下

echo StarRating::widget([
      'name' => $post - > post_rate,
      'value' => isset($post - > post_rate) ? $post - > post_rate : 0,
      'pluginOptions' => [
        'size' => 'xs',
        'filledStar' => '★',
        'emptyStar' => '☆',
        'showCaption' => false,
      ],
      'pluginEvents' => [
        "rating:change" => "function() { alert('ok'); }"
      ],
相关问题