ember.js从视图或控制器挣扎过渡到 [英] ember.js struggling with transitionTo from view or controller

查看:159
本文介绍了ember.js从视图或控制器挣扎过渡到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从控制器或视图调用路由的正确方法是什么?例如我有一个有很多行的表。每行View都有一个应该调用路由器的点击方法。它无法正常工作,无法从控制器或视图导航应用程序。



以下是一个示例: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆