我在2 textarea上用不同的id初始化2个tinyMCE编辑器:
var variable_array = {id:'cName', test:'mon test'};
tinymce.init({
selector: "#model_editor",
entity_encoding : "raw",
encoding: "UTF-8",
theme: "modern",
height: "500px",
width: "100%",
variables_list : variable_array,
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern modelinsert"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image print preview media | forecolor backcolor emoticons",
toolbar2: "variable_insert | question_insert",
image_advtab: true,
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
]
});
tinymce.init({
selector: "#headerfooter_editor",
entity_encoding : "raw",
encoding: "UTF-8",
theme: "modern",
height: "500px",
width: "100%",
variables_list : variable_array,
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern modelinsert"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image print preview media | forecolor backcolor emoticons",
toolbar2: "variable_insert | question_insert",
image_advtab: true,
init_instance_callback : "mceInitInstance",
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
]
});
两个编辑器都正确初始化。 然后为了在每个上设置不同的内容,我尝试获取编辑器实例对象id:
var editor_id = tinyMCE.get('#headerfooter_editor');
console.log(editor_id);
返回null:/
我还尝试在控制台中获取第二个init回调的结果:
function mceInitInstance(inst) {
console.log("Editor: " + inst.editorId + " is now initialized.");
它返回:编辑器:undefined现在已初始化。
我想做以下事情:
tinyMCE.get('#headerfooter_editor').setContent(data.content);
但当然它会返回一个错误:Uncaught TypeError:无法读取null的属性'setContent'
我不明白什么是错的以及为什么我无法获得编辑器实例ID:/
答案 0 :(得分:8)
您的编辑应该可以使用tinymce.get('model_editor')
和tinymce.get('headerfooter_editor')
。
提示:tinymce.editors
包含已初始化的所有编辑器实例。
您可以遍历该数组以获取所有数据:
for (var i = 0; i < tinymce.editors.length; i++)
{
console.log("Editor id:", tinymce.editors[i].id);
}
答案 1 :(得分:4)
而不是:
tinyMCE.get('#headerfooter_editor').setContent(data.content);
使用
tinyMCE.get('headerfooter_editor').setContent(data.content);
删除#
答案 2 :(得分:0)
我遇到了同样的问题。 错误消息是:
void ConnectSocket()
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
return;
}
skt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct hostent* host;
host = gethostbyname("127.0.0.1");
SOCKADDR_IN sockAddr;
sockAddr.sin_port = htons(45444);
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
if (connect(skt, (SOCKADDR*)&sockAddr, sizeof(sockAddr)) != 0) {
return;
}
}
但是我的错误是我在启动tinymce编辑器之前尝试TypeError: tinymce.get(...) is null
。
tinymce.get(...)