我是Ember.js的新手,在开发应用程序时我发现了新的路由器API.合并后根本没有文件(除此之外 - https://gist.github.com/3981133)
我不知道如何开始将我的应用程序转换为新的路由器API.这个"演练"并没有多大帮助.
1)如何将模板连接到命名插座,例如{{outlet main}}?
2)我使用App.router.someController和App.router.get('store').findAll()和.find()全部,应该用什么代替?
3)html中的把手标签有什么变化<script type="text/x-handlebars" data-template-name="templateName">吗?
我现在能想到的一切......
我刚刚在一个小例子项目中完成了这个升级
https://github.com/toranb/ember-code-camp
直接回答你的一些问题
1)没有更多的connectOutlets噪音 - 只是将路线映射到一个ember路线类/对象.这种方法是非常基于惯例的btw(模板/视图/控制器/路由都匹配)
CodeCamp.Router.map(function(match) {
match("/").to("sessions");
match("/session/:session_id").to("session"); //no route needed -ember will apply the context for you
match("/speaker/:speaker_id").to("speaker"); //same as above so long as my handlebars template name matches (speaker for this route)
});
CodeCamp.SessionsRoute = Ember.Route.extend({
setupControllers: function(controller) {
controller.set('content', CodeCamp.Session.find());
}
});
Run Code Online (Sandbox Code Playgroud)
2 a)你这样在路由器中获得商店
App.YourObject.find()
Run Code Online (Sandbox Code Playgroud)
2 b)您可以在控制器内提交商店
this.get('store').commit()
Run Code Online (Sandbox Code Playgroud)
3)除了路线相关的助手之外,我的把手的东西没有变化
I remove action helpers defined with <a {{action and used linkTo instead
{{#linkTo 'session' session}}View Session Details{{/linkTo}}
Run Code Online (Sandbox Code Playgroud)