从子路由中的组件触发对父路由的操作

时间:2018-09-11 06:41:32

标签: ember.js

在我的应用程序中,我目前有一个父路由来管理我的查询参数。我有一个使用闭包操作重置这些参数的组件。当前的实现工作正常,外观如下:

// Component

import Component from '@ember/component';

export default Component.extend({
  tagName: '',
  actions: {
    actionTest() {
      this.get('onClick')()
    }
  }

});


  <div class="text-muted" style="cursor: pointer" {{action "actionTest"}}><small>{{text}}</small></div>

// Parent Route Controller

import Controller from '@ember/controller';

export default Controller.extend({

  actions: {
    resetAllParams() {
      this.set('param1', null)
      this.set('param2', null)
    }
  }

});

// Template

{{reset-params-button onClick=(action "resetAllParams") text="Reset Filters" size="xs"}}

我想将组件从父路线模板移动到子路线模板。当我这样做时,我将不再具有重置参数的能力-我的理解是,无法在子路径上操纵父路径的参数。

我认为我需要在关闭动作功能方面增加一些步骤,但是我不太了解。我尝试使用Ember Route Action Helper,但这似乎不适用于此用例。

我尝试通过添加以下内容来“搞怪”该动作:

  // Sub-Route Template

{{reset-params-button onClick=(action "resetAllParams") text="Reset Filters" size="xs"}}

// Sub Route Controller

import Controller from '@ember/controller';

export default Controller.extend({
resetAllParams(){}
});

但是从组件控制器中的操作中发现了'this.get is not a function'错误。

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:2)

您可以将父级的路由控制器注入子级的路由控制器。在孩子的路线控制器中:

df3=df2[df2['product'].str.contains("|".join(df.keywords))]
df3.to_csv('your_path_to_new_csv',index=False)

希望这会有所帮助。有关注入的更多信息,请参见https://guides.emberjs.com/v3.4.0/applications/dependency-injection/#toc_ad-hoc-injections

相关问题