简体   繁体   English

Ember.js的新增功能,我可以呈现除根应用程序模板之外的所有模板

[英]New to Ember.js, I can render all templates except my root application template

I apologize in advanced if this is a simple mistake or I'm not aware of something very obvious. 如果这是一个简单的错误,或者我不知道有什么明显的问题,我深表歉意。 I've looked through other users problems on StackOverflow but still can't get mine to work. 我已经查看了StackOverflow上的其他用户问题,但仍然无法正常工作。 What am I doing wrong? 我究竟做错了什么? I'm taking a tutorial online and my code looks identical to my instructors. 我正在在线学习教程,我的代码看起来与我的老师相同。

My problem is that I can get Ember to render my templates of "about", "about/team", "contact" through typing my routes into the URL in my browser, but as soon as I add a handlebars template to my application (which I plan on then using an unordered list to navigate to those routes/templates) it wont render my application template. 我的问题是,我可以通过在浏览器中的URL中输入路线来让Ember呈现“ about”,“ about / team”,“ contact”模板,但是,一旦我向应用程序添加了车把模板(我计划使用一个无序列表导航到那些路由/模板),它不会呈现我的应用程序模板。

Here is my code. 这是我的代码。

<html>
<head>
  <title>Let's Learn Ember.js</title>

    <script src="js/libs/jquery-1.10.2.js"></script>
    <script src="js/libs/handlebars-1.0.0.js"></script>
    <script src="js/libs/ember.js"></script>

<script>
  window.App = Ember.Application.create();

  App.Router.map(function(){
    this.resource("about", function(){
      this.route("team")
    });
    this.route("contact");

  });
</script>
</head>
<body>
  <script type="text/x-handlebars" data-template-name="application">

  <nav>
    <ul>
      <li>{{#linkTo "index"}}Home{{/linkTo}}</li>
      <li>{{#linkTo "about"}}About{{/linkTo}}</li>
        <ul>
          <li>{{#linkTo "about.team"}Team{{/linkTo}}</li>
        </ul>
      </li>
      <li>{{#linkTo "contact"}Contact{{/linkTo}}</li>
    </ul>
  </nav>

  {{outlet}}
  </script>


  <script type="text/x-handlebars" data-template-name="index">
    <h1>Welcome to Ember.js </h1>
  </script>

  <script type="text/x-handlebars" data-template-name="about">
    <h1>About Page</h1>
    {{outlet}}
  </script>

  <script type="text/x-handlebars" data-template-name="about/team">
    <h2>here is our team!</h2>
  </script>

  <script type="text/x-handlebars" data-template-name="contact">
    <h1>Please contact us!</h1>
  </script>

</body>
</html>

EDIT Turns out that it's because I did not end my double curly brackets on my handlebars with my links to "team" and "contacts. 编辑结果是因为我没有在我的车把上用指向“团队”和“联系人”的链接结束双括号。

Sorry for the stupid question. 很抱歉这个愚蠢的问题。

You're missing some closing parenthesis on the link-to's. 您缺少指向链接的右括号。 Here it is with the fix 修复就在这里

  <li>{{#linkTo "about.team"}}Team{{/linkTo}}</li>
    </ul>
  </li>
  <li>{{#linkTo "contact"}}Contact{{/linkTo}}</li>

Easy thing to miss! 容易错过的事情! Highly suggest keeping your console up in your browser, it'll catch parse errors. 强烈建议您将控制台保持在浏览器中,这样会捕获解析错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM