2013-01-03 52 views
0

我有一个设置屏幕,它由一个侧栏和一个正文组成。正文可以有一个表单来更新用户的个人资料或密码。如何在新的Ember.js路由器API中嵌套视图?

路由看起来是这样的:

App.Router.map(function(match) { 
    (match("/")).to("index"); 
    (match("/user")).to("user", function(match) { 
    (match("/")).to("userIdx"); 
    (match("/settings")).to("userSetup", function(match) { 
     (match("/")).to("userSetupIdx"); 
     (match("/profile")).to("userSetupProfile"); 
     (match("/password")).to("userSetupPassword"); 
    }); 
    }); 
}); 

像这样的包装设置模板:

<script type="text/x-handlebars" data-template-name="userSetup"> 
    <div class='sidebar'> 
    Sidebar 
    </div> 
    <div class='main'> 
    Setup <br/> 
    {{outlet}} 
    </div> 
</script> 

一个完整的例子可以在这里找到: http://jsfiddle.net/stephanos/mgp7F/6/

什么是正确的方法在Ember.js中做到这一点?

编辑

随着sly7_7的帮助下,我设法使上述工作的小提琴:http://jsfiddle.net/ygvsS/9/。我所做的只是重命名从userSetup(模板,视图,路线)到setup。但显然这不是一个解决方案(因为我也有appSetup)。

+0

我发现这个小提琴这确实类似的东西(http://jsfiddle.net/mhfs/Y93qQ/8/) - 似乎出口是“自动的”连接到当模板和路由匹配 – stephanos

回答

1

我觉得我已经做了,你在找什么,根据您的评论例如:http://jsfiddle.net/rt8fv/

路由器代码:

App.Router.map(function(match){ 
    match('/').to('home'); 
    match('/about').to('about'); 
    match('/contributors').to('contributors', function(match){ 
    match('/').to('contributorsIndex'); 
    match('/:contributor_id').to('contributor', function(match){ 
     match('/').to('contributorIndex'); 
     match('/details').to('contributorDetail'); 
     match('/repos').to('contributorRepos'); 
    }); 
    }); 
}); 

也许相关的问题:Best approach to fetch data in every state of app

+0

的名字,我周围玩了一下我的代码,它似乎(! ),当我的模板/视图被称为“设置”它的作品,当它被称为“userSetup”它不 - 错误? – stephanos

+0

我吓坏了,我真的不明白你想要什么。你能否更新你的问题,描述你期望哪些内容? –

+0

我不知道您所使用的余烬版本,但如果它的前https://github.com/emberjs/ember.js/commit/3920af6a018ac6147e5534049b751ff0b4eeaae3,你应该使用下划线的模板名称仅 –