EmberJS 模板多段
描述
如果路由是嵌套的,您可以为每个动态段提供模型或标识符。
语句
App.Router.map(function() {
this.resource('info');
this.resource('records', { path: 'records/:records_id' });
});
例子
<!DOCTYPE html>
<html>
<head>
<title>Emberjs Template Multiple Segments</title>
<!-- CDN's -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.min.js"></script>
<script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script>
<script src="https://builds.emberjs.com/release/ember.debug.js"></script>
<script src="https://builds.emberjs.com/beta/ember-data.js"></script>
</head>
<body>
<script type="text/x-handlebars">
<!-- info and records are the resouce names -->
{{#link-to 'info'}}Fruits{{/link-to}}
{{#link-to 'records' recoModel}}Some Record{{/link-to}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="info">
<p>Some Fruits</p>
<ul>
<li>Orange</li>
<li>Banana</li>
</ul>
</script>
<script type="text/x-handlebars" data-template-name="records">
<p>Some Records</p>
{{name}}
</script>
<script type="text/javascript">
App = Ember.Application.create();
App.Router.map(function() {
this.resource('info');
//Defining Multiple Segmnets
this.resource('records', { path: 'records/:records_id' });
});
App.ApplicationController = Em.Controller.extend({
recoModel: function(){
//return the records value to the called resources
return {records_id:1, name:'Docs List'}
}.property()
});
</script>
</body>
</html>
输出
让我们执行以下步骤,看看上面的代码如何工作:
将上面的代码保存在temp_link_multiple_segm.html文件中
在浏览器中打开此HTML文件。