【问题标题】:yii2 summernote widget set toolbar optionsyii2 summernote 小部件设置工具栏选项
【发布时间】:2017-01-31 00:19:48
【问题描述】:

我在 Yii2 中实现了由 marqu3s\summernote\Summernote 扭曲的 Summernote; https://github.com/undeman/yii2-summernote

但我无法添加 Summernote 文档中显示的工具栏选项: http://summernote.org/deep-dive/

这就是我尝试使用它的方式,但是当我添加工具栏选项时,工具栏就会消失。

    $tabReport .= $form->field($model, 'ysk')->widget(Summernote::className(), [
    'clientOptions' => [
        'placeholder' => 'You can write here some important public notes to be display on top of the report...',
        'minHeight' => 100,
        'toolbar' => [
            'style' => ['bold', 'italic', 'underline', 'clear'],
        ],
    ],
  ]
);

有什么线索吗?

【问题讨论】:

    标签: php yii2 yii2-advanced-app summernote


    【解决方案1】:

    你的数组格式错误:

    'toolbar' => [
        'style' => ['bold', 'italic', 'underline', 'clear'],
    ],
    

    会产生js:

    'toolbar': {'style': ['bold', 'italic', 'underline', 'clear']}
    

    要生成所需的 js,请使用与 javascript 中相同的结构,即:

    'toolbar' => [
         ['style': ['bold', 'italic', 'underline', 'clear']]
    ]
    

    如果是你的your answer

    'toolbar' => [
        ['style', ['style']],
        ['font', ['bold', 'italic', 'underline', 'clear']],
        ['fontname', ['fontname']],
        ['color', ['color']],
        ['para', ['ul', 'ol', 'paragraph']],
        ['height', ['height']],
        ['table', ['table']],
        ['insert', ['link', 'picture', 'hr']],
        ['view', ['fullscreen', 'codeview']],
        ['help', ['help']],
    ]
    

    【讨论】:

      【解决方案2】:

      看来工具栏选项必须直接用js贴出来。

      我所做的是在主客户端选项中添加一个 id:

          $tabReport .= $form->field($model, 'ysk')->widget(Summernote::className(), [
          'clientOptions' => [
              'placeholder' => 'You can write here some important public notes to be display on top of the report...',
              'minHeight' => 100,
              'id' => 'ysk-summernote',
          ],
        ]
      );
      

      然后在我的app.js中通过js添加工具栏选项(或者在视图中注册更好)

          $('#book-ysk').summernote({
          toolbar: [
              ['style', ['style']],
              ['font', ['bold', 'italic', 'underline', 'clear']],
              ['fontname', ['fontname']],
              ['color', ['color']],
              ['para', ['ul', 'ol', 'paragraph']],
              ['height', ['height']],
              ['table', ['table']],
              ['insert', ['link', 'picture', 'hr']],
              ['view', ['fullscreen', 'codeview']],
              ['help', ['help']],
          ]
      });
      

      而且像魅力一样工作

      【讨论】:

        猜你喜欢
        • 2018-01-05
        • 2015-05-02
        • 2018-09-04
        • 2014-01-09
        • 1970-01-01
        • 2015-10-31
        • 2019-07-19
        • 2021-12-11
        • 2015-02-24
        相关资源
        最近更新 更多