试图按照这个例子(现在已经将 ember 更新到 1.0rc2),我想嵌套模板来开始。{{outlet}}
我在模板中有第一个附加项home
,我希望它包含两个嵌套视图(一个“简历”span9
和另一个“工具表” span3
,供引导爱好者使用)。“简历”将再次具有嵌套模板,但一旦我能通过第一级,我想我可以。
根据这个SO?,以及我编辑的JS Fiddle 答案,我有点看到它是如何完成的,但是,答案在咖啡脚本中,并且示例中的路由器比我能理解的要复杂一些(使用connectOutlets
,给定它的一些助手方法,我自己有点理解。
最终结果应该看起来像这样 fiddle。
但是我如何让其他模板在家庭路由器中呈现,因为sections
路由器和items
路由器位于不同的路径上,但是,这些将是索引路由的一部分/
?我是否需要多个{{outlets}}
?,以及如何将适当的模板路由到适当的插座占位符?
信息:
DEBUG: -------------------------------
DEBUG: Ember.VERSION : 1.0.0-rc.2
DEBUG: Handlebars.VERSION : 1.0.0-rc.3
DEBUG: jQuery.VERSION : 1.9.1
DEBUG: -------------------------------
索引.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Resume Builder</title>
<meta name="description" content="A way to create a tailored resume from my CV" />
<meta name="author" content="Chris Frisina" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet" />
<link href="css/RB.css" rel="stylesheet" />
</head>
<body>
<script src="js/libs/jquery-1.7.1.js"></script>
<script src="js/libs/jquery.lorem.js"></script>
<script src="js/libs/bootstrap.min.js"></script>
<script src="js/libs/handlebars-1.0.0.beta.6.js"></script>
<!-- // <script src="js/libs/ember1.js"></script> -->
<script src="js/libs/ember2.js"></script>
<script src="js/RB.js"></script>
<script type="text/x-handlebars" data-template-name="application">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<div class="brand home" {{bindAttr class="isHome:active"}} {{action "doHome"}}>Chris Frisina</div>
<div class="nav-collapse pull-right">
<ul class="nav">
<li class="sections"><a>1</a></li>
<li class="sections"><a>2</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index">
<h3 class="demo-panel-title">This is the index template</h3>
{{home}}
</script>
<script type="text/x-handlebars" data-template-name="home">
<div class="row-fluid">
<!-- This is where I resume template should be placed -->
{{resume}}
<!-- This is where I tooltable template should be placed -->
{{tooltable}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="resume">
<div class="span9">
<h1>Viewer</h1>
</div>
</script>
<script type="text/x-handlebars" data-template-name="tooltable">
<div class="span3">
<div id="tooltable" class="tooltable hero-unit affix">
<h1>Tooltable</h1>
<p>Selector 1</p>
<p>Selector 1</p>
</div>
</div>
</script>
</body>
</html>
应用程序.js:
// Attach the application to window
window.RB = Ember.Application.create({});
// Define the main application controller. This is automatically picked up by
// the application and initialized.
RB.ApplicationController = Ember.Controller.extend({
});
RB.ApplicationView = Ember.View.extend({
templateName: 'application'
});
// Router
RB.Router = Ember.Router.extend({
});
RB.Router.map(function(){
});
// Home
RB.HomeController = Ember.Controller.extend({
});
RB.HomeView = Ember.View.extend({
templateName: 'home',
});
// Resume
RB.ResumeController = Ember.ObjectController.extend({
});
RB.ResumeView = Ember.View.extend({
templateName: 'resume'
});
// Tooltable
RB.TooltableController = Ember.ObjectController.extend({
});
RB.TooltableView = Ember.View.extend({
templateName: 'tooltable'
});
//Defer the start until advanceReadiness() is complete
// cant init RB manually, must use advanceReadiness(), which needs defer...
RB.deferReadiness();
// var test = function() {
RB.advanceReadiness();
// });