我也在尝试相同的方法。最后我得到了一个解决方案。所以我在这里分享它。它可以帮助其他人。
<script type="text/javascript">
// Menu code
var config = {
toolbar: [],
removePlugins : 'pastetext,clipboard'
};
var editor = CKEDITOR.appendTo('ckeditor', config);
editor.on( 'instanceReady', function(e) {
var e = e.editor;
// Commands
e.addCommand("cv_claimant_Birthdate", {
exec: function(e) {
e.insertText("\{\!claimant.Birthdate\}");
}
});
e.addCommand("cv_claimant_Name", {
exec: function(e) {
e.insertText("\{\!claimant.Name\}");
}
});
e.addCommand("cv_claim_Name", {
exec: function(e) {
e.insertText("\{\!claim.Name\}");
}
});
e.addCommand("cv_claim_CreatedDate", {
exec: function(e) {
e.insertText("\{\!claim.CreatedDate\}");
}
});
// Listener
e.contextMenu.addListener(function(element, selection) {
return {
cv: CKEDITOR.TRISTATE_ON
};
});
// Menu Groups; different numbers needed for the group separator to show
e.addMenuGroup("cv", 500);
e.addMenuGroup("cv_people", 100);
e.addMenuGroup("cv_claim", 200);
// Menus (nested)
e.addMenuItems({
// Top level
cv: {
label: "Insert Merge Field",
group: "cv",
getItems: function() {
return {
cv_claimant: CKEDITOR.TRISTATE_OFF,
cv_claim: CKEDITOR.TRISTATE_OFF,
};
}
},
// One sub-menu
cv_claimant: {
label: "Claimant Person (claimant)",
group: "cv_people",
getItems: function() {
return {
cv_claimant_Birthdate: CKEDITOR.TRISTATE_OFF,
cv_claimant_Name: CKEDITOR.TRISTATE_OFF,
};
}
},
// These run commands
cv_claimant_Birthdate: {
label: "Birthdate (Birthdate: date)",
group: "cv_people",
command: "cv_claimant_Birthdate"
},
cv_claimant_Name: {
label: "Full Name (Name: string)",
group: "cv_people",
command: "cv_claimant_Name"
},
// Another sub-menu
cv_claim: {
label: "Claim (claim)",
group: "cv_claim",
getItems: function() {
return {
cv_claim_CreatedDate: CKEDITOR.TRISTATE_OFF,
cv_claim_Name: CKEDITOR.TRISTATE_OFF,
};
}
},
// These run commands
cv_claim_Name: {
label: "Claim Number (Name: string)",
group: "cv_claim",
command: "cv_claim_Name"
},
cv_claim_CreatedDate: {
label: "Created Date (CreatedDate: datetime)",
group: "cv_claim",
command: "cv_claim_CreatedDate"
},
});
});
</script>