mithril.js与CKEditor有关

时间:2016-05-20 02:34:56

标签: ckeditor mithril.js

我使用mithril.js + CKEditor

编写了这段代码
<body>
    <script>
        var frm = {};

        frm.vm = (function () {
            var vm = {};

            vm.afterLoad = function () {
                CKEDITOR.replace( 'editor1' );
            };

            vm.btnClick = function () {
                console.log(document.getElementById('editor1').value);
            };

            return vm;
        })();

        frm.controller = function () {

        };

        frm.view = function (controller) {
            return m("div", {config: frm.vm.afterLoad}, [
                m("textarea", {id: "editor1"}),
                m("button", {onclick: frm.vm.btnClick}, "Click here to see the text you've typed")
            ]) 
            ;
        };

        m.mount(document.body, frm);
    </script>
</body>

但是当我点击按钮时,我看到了这个错误:

Uncaught The editor instance "editor1" is already attached to the provided element.

console.log()打印一个空行。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我发现了问题。要获得CKEditor的值,需要使用

CKEditor.instance.nameoftextarea.getData()