【问题标题】:Getting: Uncaught TypeError: Invalid template!...in mustache.js获取:未捕获的类型错误:无效的模板!...在 mustache.js
【发布时间】:2015-10-11 23:08:16
【问题描述】:

我一直在尝试实现外部模板,但无济于事。 这是完整的错误:

Uncaught TypeError: Invalid template! Template should be a "string" but "undefined" was given as the first argument for mustache#render(template, view, partials)

我将browserify-shim 用于其他一些依赖项,但它们运行良好,并且我没有从终端收到错误(来自该任务)。只是外部模板加载给我带来了问题。

function templateLoader(e) {
        var doc = document,
            event = EventUtility.getEvent(e),
            target = EventUtility.getTarget(event);
            $("body").load("templates/index.html #overlay", function() {
                var temp1 = $('#overlay').html();
                var output = Mustache.render(temp1);
                $("body").html(output);
            });

    }

var flimFlam = document.getElementById('Container');
EventUtility.addHandler(flimFlam, 'click', templateLoader);

提前非常感谢!

【问题讨论】:

    标签: javascript jquery templates mustache


    【解决方案1】:

    试着把所有东西都放进去

    $(document).ready(function(){
    
    
    });
    

    我遇到了同样的错误,它对我有用。

    【讨论】:

    • 是的,这行得通,我的代码在 windows.onload 方法中。我现在搬进了 document.ready。
    【解决方案2】:

    因为您的 Mustache 模板可能嵌套在渲染模板中。将它们分开,这个错误应该会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多