Javascript $.Mustache.load和$.Mustache.render
我有下一个问题。我有以下代码用于加载模板:Javascript $.Mustache.load和$.Mustache.render,javascript,html,mustache,jquery-templates,Javascript,Html,Mustache,Jquery Templates,我有下一个问题。我有以下代码用于加载模板: $.Mustache.load( "./templates/news/home.tpl" ); 即: function load(url, onComplete) { return $.ajax({ url: url, dataType: options.externalTemplateDataType }).done(function (templates) {
$.Mustache.load( "./templates/news/home.tpl" );
即:
function load(url, onComplete)
{
return $.ajax({
url: url,
dataType: options.externalTemplateDataType
}).done(function (templates)
{
$(templates).filter('script').each(function (i, el)
{
add(el.id, $(el).html());
});
if ($.isFunction(onComplete)) {
onComplete();
}
});
}
function render(templateName, templateData) {
alert(!has(templateName));
if (!has(templateName)) {
if (options.warnOnMissingTemplates) {
$.error('No template registered for: ' + templateName);
}
return '';
}
return getMustache().to_html(templateMap[templateName], templateData, templateMap);
}
当我点击时,进入另一页:
$("body").append($.Mustache.render(pageId + "-template", data));
即:
function load(url, onComplete)
{
return $.ajax({
url: url,
dataType: options.externalTemplateDataType
}).done(function (templates)
{
$(templates).filter('script').each(function (i, el)
{
add(el.id, $(el).html());
});
if ($.isFunction(onComplete)) {
onComplete();
}
});
}
function render(templateName, templateData) {
alert(!has(templateName));
if (!has(templateName)) {
if (options.warnOnMissingTemplates) {
$.error('No template registered for: ' + templateName);
}
return '';
}
return getMustache().to_html(templateMap[templateName], templateData, templateMap);
}
因此,我的答案是:如果(!has(templateName)),因为没有加载该模板,那么问题出在哪里?模板没有加载,因为我必须设置完整路径-www/Templates/news/home.tpl
有时会出现延迟,而且WP不会加载带有*.tpl格式的模板,所以我将其更改为txt,并且所有操作都正常运行为什么不使用*.html扩展名?编辑也会将其识别为HTML语法。:)