CKEditor commitContent起作用,但是setupContent为属性返回null

时间:2019-06-19 00:01:21

标签: ckeditor

我正在尝试提交自定义ckeditor插件的属性,以便在选择元素时,onShow()会填充所有属性。 commitContent似乎在提交后返回正确的值,从而调用element.getAttribute()。但是,调用setupContent()之后的element.getAttribute()为null。某些代码是从ckeditor教程https://ckeditor.com/docs/ckeditor4/latest/guide/plugin_sdk_sample_2.html

中复制/粘贴的
contents: [
            {
                //TAB - BASIC
                id: 'tab-basic',
                label: 'Basic',
                elements: [
                     { 
                        //NAME
                         type: 'text',
                         label: "Name",
                         id: 'name',
                         'default': "ml-model",
                         setup: function( element ) {
                             this.setValue( element.getAttribute( "name" ) );
                             alert( 'setting up: ' + element.getAttribute( "name" ));
                         },
                         commit: function( element ) {
                             element.setAttribute( "name", this.getValue() );
                             alert( 'committing: ' + element.getAttribute( "name" ));
                         }
                     },

这是有问题的属性

onShow: function() {
            var selection = editor.getSelection();
            var element = selection.getStartElement();
            //alert( 'test: ' + element.getAttribute( "name" ));
            if ( element )
                element = element.getAscendant( 'ml-model', true );

            if ( !element || element.getName() != 'ml-model' ) {
                element = editor.document.createElement( 'ml-model' );
                this.insertMode = true;
            }
            else
                this.insertMode = false;

            this.element = element;
            if ( !this.insertMode ) {
                this.setupContent(this.element);
            }
        },

    onOk: function() {          
        var dialog = this;
            var abbr = this.element;
            this.commitContent( abbr );


            if ( this.insertMode) {
                var content = strBuild();
                var element = CKEDITOR.dom.element.createFromHtml(content);
                var instance = this.getParentEditor();
                instance.insertElement(element);
            }

这是我的onShow()和onOk()函数,应提交和设置内容。

0 个答案:

没有答案