0

我按照本指南为 trumbowyg 创建了一个自定义下拉列表,但我一直坚持如何在单击下拉按钮时真正插入文本。

$('.editor').trumbowyg({
    btnsDef: {
        tagSelect: {
            fn: () => {
                // how to insert test to cursor's position?
            },
            text: 'Name Tag',
            hasIcon: false
        },
        detailsType: {
            dropdown: [
                'tagSelect',
            ],
            title: 'Client Tag',
            hasIcon: false
        }
    },
    btns: [
        ['detailsType']
    ]
})
4

1 回答 1

0

我通过使用插件“提及”来做到这一点。

使用那个插件就这么简单:

$('#editorid').trumbowyg({
    plugins: {
                mention: {
                    source: [
                        { mergetag: '[RECIPIENT_NAME]', name: 'Full name of the recipient' },
                        { mergetag: '[RECIPIENT_NAME_FIRST]', name: 'First name of the recipient' },
                        { mergetag: '[SENDER_NAME]', name: 'Name of sender' },  
                        { mergetag: '[SENDER_MAIL]', name: 'Sender email' },  
                        { mergetag: '[SIGNATURE]', name: 'Senders mailsignature' }
                    ],
                    formatDropdownItem: function (item) {
                        return item.name + ' ' + item.mergetag;
                    },
                    formatResult: function (item) {
                        return item.mergetag;
                    }
                }
            }
});

更多信息在这里:https ://alex-d.github.io/Trumbowyg/demos/plugins/mention.html

于 2021-06-29T13:00:12.743 回答