ember.js从视图或控制器挣扎过渡到 [英] ember.js struggling with transitionTo from view or controller
问题描述
以下是一个示例: http://jsfiddle.net/arenoir/Cs938/
App.TableView = Ember.CollectionView.extend({
tagName:'table',
contentBinding:'controller.rows',
itemViewClass:Ember.View.extend({
tagName:'tr',
template:Ember.Handlebars.compile(< td> {{view.content.name}}),
click:function(){
var router,tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.goTab (标签);
}
})
});
以下帖子很有帮助。 EmberJS:如何从一个路由器过渡到控制器的操作。
这是您在视图中过渡逻辑的当前实现:
点击:function(){
var router,tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.goTab(tab);
}
将其更改为此实现:
点击:function(){
var router,tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.transitionTo(tab);
}
这修复了小提琴。但是从你的例子来看,还不清楚,为什么你想在你的视图中进行触发器转换。路由器中总是会发生状态管理。
另一个尴尬的事情是你从ApplicationController得到你的行。为什么不使用ArrayController。所以从我的观点看,似乎有一些事情在错误的地方。
What is the proper way to call a route from the controller or view. For instance I have a table with many rows. Every row View has a click method that should call the router. It doesn't work I am having trouble navigating the app from the controller or view.
Here is an example: http://jsfiddle.net/arenoir/Cs938/
App.TableView = Ember.CollectionView.extend({
tagName: 'table',
contentBinding: 'controller.rows',
itemViewClass: Ember.View.extend({
tagName: 'tr',
template: Ember.Handlebars.compile("<td>{{view.content.name}}"),
click: function(){
var router, tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.goTab(tab);
}
})
});
The following post is helpful. EmberJS: How to transition to a router from a controller's action.
That is the current implementation of the Transitioning Logic in your view:
click: function(){
var router, tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.goTab(tab);
}
Change it to this implementation:
click: function(){
var router, tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.transitionTo(tab);
}
This fixes the fiddle. But from your example it is not clear, why you want to do trigger Transitions in your View. Statemanagement should always happen in the Router. Another awkward thing is that you get your rows from the ApplicationController. Why don't u use an ArrayController. So from my point of view, there seem to be some things in the wrong place.
这篇关于ember.js从视图或控制器挣扎过渡到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!