我正在使用 TinyMCE,并尝试通过 API 动态加载模板。但是,即使使用基本返回,也不会加载模板(例如将模板列表设置为变量)。它们确实从外部 JSON 文件(硬编码)加载。那么我的问题是:如何返回或呈现自定义 TinyMCE 模板?
例如:
这有硬编码的模板,所以它可以工作:
templates: "/Content/data/templates.json"
但我正在努力实现(在基本层面上):
templates:
function () {
var test =
{ title: 'Test template 1', content: 'Test 1' };
return tinymce.util.JSON.parse(test); // doesn't work
//return JSON.stringify(templates); // doesn't work
},
在原始规模上(代码不完整):
templates:
function () {
$.getJSON('/Template', function (result) {
var data = {};
$.each(result.ResponseObject, function (index, value) {
data.title = value.Name;
data.description = value.Name;
data.content = value.Description;
// can't figure out how to return variable
});
});