Handlebars-需要插件不编译模板

时间:2014-09-05 13:31:08

标签: jquery requirejs handlebars.js

我正在使用require手柄插件(https://github.com/SlexAxton/require-handlebars-plugin),我也集成到我的应用中......

这是我的模板:(作为样本)

<div class="best plugin ever">
  This is my {{ adjective }} template.
</div>

在view.js中我调用模板并编译:

define([
    'jquery',
    'underscore',
    'backbone',
    'hbs!scripts/login/template/login1Temp.hbs'],
    function ($,_,Bacbone,loginTemplate) {
        "use strict";
        socialApp = window.socialApp || {};

        socialApp.loginView = Bacbone.View.extend({
            el:'div#header',
            initialize:function(){
                var html = loginTemplate({adjective: "favorite"}) //i am using handlebars temp. 
                this.$el.html("<p>This is weekend! </p>"); //it works
                this.$el.html(html); //it not working, i am getting my static html duplicates!
            }
        });

        return socialApp.loginView;
    }
);

1 个答案:

答案 0 :(得分:0)

define删除文件扩展名后,它工作正常。可怜的医生让这场斗争成为现实。

define([
    'jquery',
    'underscore',
    'backbone',
    'hbs!scripts/login/template/login1Temp'], //removed the extension.
    function ($,_,Bacbone,loginTemplate) {
        "use strict";
        socialApp = window.socialApp || {};

        socialApp.loginView = Bacbone.View.extend({
            el:'div#header',
            initialize:function(){
                var html = loginTemplate({adjective: "favorite"}) //i am using handlebars temp. 
                this.$el.html("<p>This is weekend! </p>"); //it works
                this.$el.html(html); //it not working, i am getting my static html duplicates!
            }
        });

        return socialApp.loginView;
    }
);