烬不显示视图

emberjs not showing view

本文关键字:视图 显示      更新时间:2023-09-26

我刚刚开始学习ember.js,我正试图将其集成到现有的rails应用程序中。我正在使用ember-rails宝石,一切看起来都很好,除了我的模板没有出现,当我在rails视图中调用{{outlet}}。下面是我的代码。

Rails视图,我希望我的ember应用程序是

<script type="text/x-handlebars" data-template-name="application">
  <h1>test</h1>
  {{outlet}}
</script>
<div id="ember-root">

这是我的ember App代码:

window.Resumecompanion = Ember.Application.create({
  LOG_TRANSITIONS: true, // basic logging of successful transitions
  LOG_TRANSITIONS_INTERNAL: true, // detailed logging of all routing steps
  rootElement: '#ember-root'
});

Resumecompanion.Router.reopen({});
Resumecompanion.JobsRoute = Ember.Route.extend({})
Resumecompanion.Router.map(function() {
  this.resource('jobs');
});

最后是车把模板位于app/assets/javascripts/templates/jobs.handlebars

<h1>Jobs</h1>
<p>Your content here.</p>
{{outlet}}

当我在作业中运行应用程序模板时。把手没有显示出来。在控制台中,我看到如下:

尝试将URL转换到/jobs

Transition #0: application: calling beforeModel钩子

Transition #0: application: calling deserialize hook

Transition #0: application: calling afterModel hook

Transition #0: jobs: calling beforeModel钩子

Transition #0: jobs: calling deserialize hook

Transition #0: jobs: calling afterModel hook

Transition #0:解析目的地路线上的所有模型;最终确定过渡。

过渡到"工作"

Transition #0: Transition COMPLETE.

Ember Debugger Active

所以我认为它实际上是路由到"工作",但我在为什么模板似乎没有渲染和显示的损失。如有任何帮助,不胜感激。

经过一些更多的播放,我发现如果我在我的rails视图中声明这个

<script type="text/x-handlebars" data-template-name="jobs">
  <h1>Jobs</h1>
  {{outlet}}
</script>

然后它呈现这个模板并正确显示。所以也许有一个命名问题,我不知道在模板?

谢谢,

Josh

当你在路由器中定义路由或资源时,它也会引用你的模板。如果没有该名称的模板,就没有要渲染的内容。所以你的假设是正确的,你需要一个"jobs"模板来帮助与你的路由器代码相对应。

如果你感兴趣,这里有一篇关于路由和资源区别的好文章。

http://blog.trackets.com/2013/02/01/ember-dot-js-router-and-template-naming-convention.html