為這些問題,博主做的努力。。。。感天動地
30個小時,700次百度,500次console.log,終於搞定這個事
1.動態創建的編輯器,無法獲取值的問題?
其實是可以獲取值得,只是,在同步之前,nice validate就做了驗證。所以,要重新發起一次驗證
2.使用kindeitor官網的this.sync也不行?
這個,確實是可以的!確實是可以把編輯器的數據同步到對應的textarea里的。
3.怎么辦?
首先,為了動態渲染編輯器,要定義好editor組件。參考上一篇文章
https://www.cnblogs.com/cn-oldboy/p/12852656.html
接着:在request-form.js編輯器editor:的配置后面,新增一個afterBlur事件
items: [
'source', 'undo', 'redo', 'preview', 'print', 'template', 'code', 'quote', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall',
'formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', 'image', 'multiimage', 'graft',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', 'remoteimage', 'about', 'fullscreen'
],
afterBlur: function() {
// 設置編輯器的同步
var self = this;
self.sync();
// 重新觸發validate事件,這樣就會通過驗證
$(that).trigger("validate");
// 觸發changed事件,是為了fiedlist的同步監聽
$(that).closest(".myeditor").trigger("changed");
},