Javascript 不同的JS语法-如何将这些属性添加到变量?
我有两个相似的js代码 这个问题更多地与js有关,而不是与库有关。 我正在使用quilljs库实现一个文本编辑器,我可以在加载库之前自定义它的设置 我已经以这种方式配置了库:Javascript 不同的JS语法-如何将这些属性添加到变量?,javascript,jquery,arrays,quill,Javascript,Jquery,Arrays,Quill,我有两个相似的js代码 这个问题更多地与js有关,而不是与库有关。 我正在使用quilljs库实现一个文本编辑器,我可以在加载库之前自定义它的设置 我已经以这种方式配置了库: var toolbarOptions = [ [{ 'font': [] }], [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'align': [] }], ['bold', 'italic', 'underline', 'strike'], /
var toolbarOptions = [
[{ 'font': [] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'align': [] }],
['bold', 'italic', 'underline', 'strike'], // toggled buttons
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
['blockquote', 'code-block'],
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[ 'link', 'video', 'formula' ],
['clean'] // remove formatting button
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
placeholder: 'Compose a post...',
theme: 'snow',
'image-tooltip': true,
'link-tooltip': true
});
$('#contenthidden').val(quill.root.innerHTML);
);
无论如何,我需要将下面的代码添加到toolbarOptions变量中,然后我必须加载quilljs等。。。
但是它的内容是完全不同的。就Javascript而言,我不明白如何将这个toolbarOptions变量的内容添加到上面的第一个变量中
var toolbarOptions = {
handlers: {
// handlers object will be merged with default handlers object
'link': function(value) {
if (value) {
var href = prompt('Enter the URL');
this.quill.format('link', href);
} else {
this.quill.format('link', false);
}
}
}
}
感谢您的帮助。查看文档时,似乎忽略了以下内容:
toolbar : { container : containerOptions, handlers : handlerOptions }
做的只是:
toolbar : containerOptions
只是一个快捷方式,因为容器
选项非常常见。因此,您必须使用第一个表单来指定处理程序选项
var toolbarOptions = {
container: [
[{ 'font': [] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'align': [] }],
['bold', 'italic', 'underline', 'strike'], // toggled buttons
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
['blockquote', 'code-block'],
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[ 'link', 'video', 'formula' ],
['clean'] // remove formatting button
],
handlers: {
// handlers object will be merged with default handlers object
'link': function(value) {
if (value) {
var href = prompt('Enter the URL');
this.quill.format('link', href);
} else {
this.quill.format('link', false);
}
}
}
}