最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Ember route not displaying template content - Stack Overflow

matteradmin5PV0评论

I am new to Ember and JS, so far the most extensive tutorials I found were using 1.0.0 pre2, but on the official site there is a very nice description and some examples of 1.0.0 pre4. I started to use that. I am stuck at routing, here is my code:

index.html

<body>
        Loaded.
        <script type="text/x-handlebars" data-template-name="application">
            In template displaying val: {{name}}

            {{#linkTo "index"}}<img class="logo">{{/linkTo}}

            <nav>
              {{#linkTo "about"}}About{{/linkTo}}
              {{#linkTo "favorites"}}Favorites{{/linkTo}}
            </nav>

        </script>

        <script type="text/x-handlebars" data-template-name="about">
            Here es the about text: {{str}}
        </script>
</body>

app.js

window.App = Ember.Application.create();

App.ApplicationView = Ember.View.extend({
templateName: 'application'
})

App.ApplicationController = Ember.Controller.extend({
name: 'test'
})

App.AboutView = Ember.View.extend({
templateName: 'about'
})

App.AboutController = Ember.Controller.extend({
str: 'my string'
})


App.Router.map(function() {
 this.route("about", { path: "/about" });
 this.route("favorites", { path: "/favs" });
});

It's almost identical to the one from the site. What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

I am new to Ember and JS, so far the most extensive tutorials I found were using 1.0.0 pre2, but on the official site there is a very nice description and some examples of 1.0.0 pre4. I started to use that. I am stuck at routing, here is my code:

index.html

<body>
        Loaded.
        <script type="text/x-handlebars" data-template-name="application">
            In template displaying val: {{name}}

            {{#linkTo "index"}}<img class="logo">{{/linkTo}}

            <nav>
              {{#linkTo "about"}}About{{/linkTo}}
              {{#linkTo "favorites"}}Favorites{{/linkTo}}
            </nav>

        </script>

        <script type="text/x-handlebars" data-template-name="about">
            Here es the about text: {{str}}
        </script>
</body>

app.js

window.App = Ember.Application.create();

App.ApplicationView = Ember.View.extend({
templateName: 'application'
})

App.ApplicationController = Ember.Controller.extend({
name: 'test'
})

App.AboutView = Ember.View.extend({
templateName: 'about'
})

App.AboutController = Ember.Controller.extend({
str: 'my string'
})


App.Router.map(function() {
 this.route("about", { path: "/about" });
 this.route("favorites", { path: "/favs" });
});

It's almost identical to the one from the site. What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

Share Improve this question asked Jan 24, 2013 at 15:11 PioPio 4,06411 gold badges47 silver badges81 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

Your application template does not have an {{outlet}}. With that in place it will work as expected.

See this jsbin for a working example.

Post a comment

comment list (0)

  1. No comments so far