$.Mustache.load and $.Mustache.render



我还有一个问题。我有这段代码来加载我的模板:

$.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();
            }
    });
}

当我点击到另一页时:

$("body").append($.Mustache.render(pageId + "-template", data));

:

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);
}

所以我的它落在:if (!has(templateName)),因为说模板没有加载,问题是什么?

模板没有加载,因为我必须设置完整的路径- www/Templates/news/home.tpl有时会有延迟,WP无法加载带有*的模板。TPL格式,所以我把它改成TXT,一切正常

为什么不使用*.html扩展名呢?编辑器也会将其识别为HTML语法。:)

最新更新