简体   繁体   English

Ember.JS:使用ember-cli创建的模板未呈现路线的属性

[英]Ember.JS: template created with ember-cli not rendering property from route

I am trying to learn Ember.JS by following the Gaslight training videos . 我正在尝试通过阅读Gaslight 培训视频来学习Ember.JS。 During "Step 1: Templating", Mitch Lloyd provides a very simple example of dynamically rendering a name property in the application template. 在“步骤1:模板化”期间,Mitch Lloyd提供了一个非常简单的示例,可以在应用程序模板中动态呈现名称属性。 I followed the instructions, but the name does not appear on the screen. 我按照说明进行操作,但名称未出现在屏幕上。 Here are the two file I edited after using ember new to create the app. 这是我使用ember new创建应用程序后编辑的两个文件。

app/templates/application.js 应用程序/模板/ application.js中

import Ember from 'ember';

export default Ember.Route.extend({
  model: function () {
    return {name: "Joe"};
  }
});

app/routes/application.hbs 应用程序/路由/ application.hbs

<h2 id="title">Welcome to Ember.js</h2>

{{name}}

I am using ember-cli version 2.12.1, emberjs version 1.13.1, and chrome version 44.0.2403.89 (64-bit). 我正在使用2.12.1版本的ember-cli,1.13.1版本的emberjs和chrome版本44.0.2403.89(64位)。 According to the Ember Inspector, the name property is available in the model. 根据Ember Inspector,名称属性在模型中可用。 I just don't understand why it is not showing up in the template. 我只是不明白为什么它没有显示在模板中。 I think it might be a problem with my version of ember-cli, because I was able to get the template to render the name property in this JSBin . 我认为这可能与我的ember-cli版本有关,因为我能够获取模板来呈现此JSBin中的name属性。

I am completely new to Ember.JS and ember-cli, so please excuse my ignorance. 我对Ember.JS和ember-cli完全陌生,所以请原谅我的无知。 Why is the application template not loading the name property from the model? 为什么应用程序模板没有从模型中加载name属性? I would really appreciate any solutions, suggestions, or advice. 我真的很感谢任何解决方案,建议或意见。 Thank you! 谢谢!

Ember, and Ember-CLI, change so quickly that many (most) tutorials, etc. are outdated. Ember和Ember-CLI的更改是如此之快,以至于许多(大多数)教程等已过时。 Because it's a property of the route, and not the controller, you should use {{model.name}} 由于它是路由的属性,而不是控制器的属性,因此应使用{{model.name}}

Yes, it's very confusing. 是的,这非常令人困惑。

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

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