yii2 summernote widget设置工具栏选项

时间:2017-01-30 14:26:52

标签: php yii2 yii2-advanced-app summernote

我正在实施Yii2的夏季音乐,由marqu3s \ 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'],
        ],
    ],
  ]
);

任何线索?

2 个答案:

答案 0 :(得分:0)

好像工具栏选项必须直接用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']],
    ]
});

像魅力一样工作

答案 1 :(得分:0)

您的数组格式错误:

'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']],
]