Ember.js - 为什么我的带有内联模板的视图没有显示
Ember.js - why is my View with inline template not displaying?
>我正在尝试获取带有内联模板的视图,以显示在有条件的车把内。在我的应用程序代码中,如果我导航到另一条路由,然后再次返回,它就会显示出来。在小提琴中,我收到有关视图的错误。
JSFiddle
<script type="text/x-handlebars" data-template-name="application">
<h1>If you click that button, I might say 'Hello!'</h1>
<button {{action 'click_me'}}>Click me</button>
{{#if controller.new_visible}}
{{#view App.MyView}}
Hello! {{/view}}
{{/if}}
</script>
var App = Ember.Application.create();
App.MyView = Ember.View.extend({});
App.ApplicationController = Ember.Controller.extend({
new_visible: false,
actions: {
click_me: function() {
alert('You clicked me!');
this.set('new_visible',true);
}
}
});
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
App.Router = Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/'
})
})
});
我做错了什么?
App
必须是全局的 - 如果您检查 JavaScript 日志,您可以看到 Handlebars 视图助手找不到名为 App.MyView
的视图。这是因为App
是在本地声明的,因此模板无法访问它。将App
定义更改为:
window.App = Ember.Application.create();
此外,您不需要扩展路由器。你可以只使用地图。例如
App.Router.map(function(){
this.route('index', {path: '/'});
});
这是一个有效的JSFiddle:http://jsfiddle.net/PkT8x/420/
相关文章:
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- FF视图源|脚本高亮显示为红色
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 如何在MVC3中显示鼠标悬停在文本上的部分视图
- 如何应用带过滤器的ng if来过滤记录,并在同一页面中显示两个不同的视图
- 为什么我的视图没有显示在角度ui视图中
- 使用PhoneGap和jQuery Mobile在android设备上显示动态列表视图
- 使用Ruby数组使用JS在视图中进行迭代和显示
- 滑动视图 - 显示下一项的预览/片段
- 在剃须刀应用程序中将视图显示为灯箱
- ember.js如何为视图显示不同的筛选列表?复杂的设置
- ng重复视图显示与JSON数据不对应
- RedirectToAction之后没有视图显示
- ASP.. NET MVC控制器/视图显示本地时间
- 离子弹出窗口视图显示在离子模态视图后面
- WinJs列表视图显示:无带ID的tile
- 完整的日历视图显示goToDate分前,下和今天
- 如何从父数组视图显示子对象视图
- CouchApp视图显示将为空结果
- 在树状视图显示中只打开一个li节点