骨干模板不会更新为新值

时间:2014-04-10 08:59:09

标签: backbone.js yeoman ejs

我和Yeoman搭建了一个骨干应用程序。我使用标准模板.ejs。发生了一些奇怪的事情。如果我从我的HTML中获取一个元素,它将更新为标准.ejs`

您的内容

当我编辑模板然后重新加载时,新内容将不会显示,并显示旧内容:

<p>your content here </p>

我的代码:

main.js

    /*global require*/
'use strict';

require.config({
    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        },
        bootstrap: {
            deps: ['jquery'],
            exports: 'jquery'
        }
    },
    paths: {
        jquery: '../bower_components/jquery/dist/jquery',
        backbone: '../bower_components/backbone/backbone',
        underscore: '../bower_components/underscore/underscore',
        bootstrap: '../bower_components/sass-bootstrap/dist/js/bootstrap'
    }
});

require([
    'backbone',
    'routes/app'
], function (Backbone, AppRouter) {
    var app = new AppRouter();
    Backbone.history.start();
});

AppRouter(App.js);

/*global define*/

define([
    'jquery',
    'backbone',
    'views/wine',
    'views/headerView'
], function ($, Backbone, WineView, HeaderView) {
    'use strict';

    var AppRouter = Backbone.Router.extend({

        routes: {
            '' : 'doSomething'
        },

        doSomething: function() {
            console.log('doSomething init');
            var headerView = new HeaderView();
        }

    });

    return AppRouter;
});

HeaderView:

    /*global define*/

define([
    'jquery',
    'underscore',
    'backbone',
    'templates'
], function ($, _, Backbone, JST) {
    'use strict';

    var HeaderViewView = Backbone.View.extend({
        template: JST['app/scripts/templates/HeaderView.ejs'],

        tagName: 'div',

        id: '',

        className: '',

        events: {
            'click .new' : 'addNew'
        },

        initialize: function () {
            this.render();
        },

        render: function () {
            $('#header').append(this.template);
        }
    });

    return HeaderViewView;
});

HeaderView.ejs

<h1>New Text</h1>

输出网站:

your content here

0 个答案:

没有答案