我正在使用来自http://jeff-collins.github.io/ment.io/#/examples的 ment.io 插件和 tinyMce 来获得编辑器支持。
一切都很好,直到我发现当我使用鼠标选择菜单项时,模型不会自动更新,尽管在编辑器中它正确显示了选定的文本。
进一步调查发现,当我们用鼠标选择后在编辑器中执行一些关键事件时,模型正在更新。
使用箭头键选择并使用 enter 或 tab 选择时,模型正在正确更新。这可能是因为,这是编辑器在早期案例中寻找的关键事件。
这是 scrnario 的小提琴链接https://jsfiddle.net/vikasnale/2p6xcssf/5/
<div ng-app="App">
<script type="text/ng-template" id="/tag-mentions.tpl">
<ul class="list-group user-search">
<li mentio-menu-item="Tag" ng-repeat="Tag in items" class="list-group-item">
<span class="text-primary" ng-bind-html="Tag.name | mentioHighlight:typedTerm:'menu-highlighted' | unsafe"></span>
</li>
</ul>
</script>
<textarea mentio-id="'tinyMceTextArea'" ui-tinymce="tinyMceOptions" mentio mentio-typed-text="typedTerm" mentio-require-leading-space="true" ng-model="Content" mentio-iframe-element="iframeElement"></textarea>
<mentio-menu id="hastmenu" mentio-for="'tinyMceTextArea'" mentio-trigger-char="'#'" mentio-items="tags" mentio-template-url="/tag-mentions.tpl" mentio-search="searchTags(term)" mentio-select="getTagTextRaw(item)"></mentio-menu>
<br/>
<p>Output Model: {{Content}}</p>
angular.module('App', ['mentio', 'ui.tinymce'])
.controller("Ctrl", ['$scope', 'mentioUtil', 函数($scope,mentioUtil) {
$scope.getTagTextRaw = function(item) {
return '<i class="mention-tag-text" style="color:#a52a2a;">' + item.name + '</i>';
};
$scope.searchTags = function(term) {
var tagsList = [];
angular.forEach($scope.allTagList, function(item) {
if (item.id.toUpperCase().indexOf(term.toUpperCase()) >= 0) {
if (tagsList.length <= 5) {
tagsList.push(item);
}
}
});
$scope.tags = tagsList;
return tagsList;
};
$scope.allTagList = [{
"id": "ctp",
"name": "#ctp"
}, {
"id": "earningRelease",
"name": "#earningRelease"
}, {
"id": "presssrelease",
"name": "#presssrelease"
}, {
"id": "inversor-conference",
"name": "#inversor-conference"
}, {
"id": "live release",
"name": "#IACLive"
}, {
"id": "reval",
"name": "#reval"
}, {
"id": "margin",
"name": "#margin"
}, {
"id": "phonecall",
"name": "#phonecall"
}, {
"id": "Q4",
"name": "#Q4"
}];
$scope.tinyMceOptions = {
init_instance_callback: function(editor) {
$scope.iframeElement = editor.iframeElement;
},
resize: false,
width: '100%',
height: 150,
plugins: 'print textcolor',
toolbar: "bold italic underline strikethrough| undo redo",
toolbar_items_size: 'small',
menubar: false,
statusbar: false
};
}
]);
注意:在使用 ment.io 和 tinymce 时会观察到此行为
无法解决这个问题..
请指教...