Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 主干网需要js_Javascript_Jquery_Node.js_Backbone.js_Gruntjs - Fatal编程技术网

Javascript 主干网需要js

Javascript 主干网需要js,javascript,jquery,node.js,backbone.js,gruntjs,Javascript,Jquery,Node.js,Backbone.js,Gruntjs,我是js的新手。我有 index.html <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="/common.css"/> </head> <body> <div id="page"></div> <script data-ma

我是js的新手。我有 index.html

<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="/common.css"/>
    </head>
    <body>
        <div id="page"></div>
        <script data-main="js/main" src="js/lib/require.js"></script>
    </body>
</html>
路由器.js

    define([
        'backbone',
        'views/scoreboard'
    ], function(
         Backbone,
         scoreboard
    ){

        var Router = Backbone.Router.extend({
            routes: {
                'scoreboard': 'scoreboardAction',
                'game': 'gameAction',
                '*default': 'defaultActions'
            },
            defaultActions: function () {
                scoreboard.show();
                scoreboard.render();

            },
            scoreboardAction: function () {
                scoreboard.show();
                scoreboard.render();
                console.log(scoreboard.render());

            },
            gameAction: function () {
                // TODO
            }
        });

        return new Router();
    });
scoreboard.js

define([
    'backbone',
    'tmpl/scoreboard'
], function(
    Backbone,
    tmpl
){

    var View = Backbone.View.extend({

        template: tmpl,
        initialize: function () {
            //console.log("Woohoho");
            //this.listenTo(this.model, "change", this.render);
        },
        render: function () {
            //console.log(this.template());
            //this.$el.html(this.template(this.model.toJSON()));
            this.template();
            this.$el.html(this.template());
        },
        show: function () {
            //console.log("show");
            this.$el.html(this.template());

        },
        hide: function () {
            alert("Hide");
            // TODO
        }

    });

    return new View();
});

如果i
console.log(this.template()),则从模板生成tmpl/scoreboard.js我将看到有效的html代码。但在浏览器中,我看不到任何内容,即白色屏幕。如何显示我的模板?

el
元素添加到视图中,如下所示:

var View = Backbone.View.extend({
    el: '#page',
    ....
var View = Backbone.View.extend({
    el: '#page',
    ....