javascript - [EmberJS] : Get selected model in child template

标签 javascript ember.js

我是 Ember 的新手,想在子 Controller /模板中获取选定的模型值。

我有一个列出工作区的边栏。每当有人单击工作区时,应用程序都会路由到 workspaces/:slug 并显示连接到该特定工作区的任务列表。

我想在子路由中显示选定的工作区 name。我该怎么做?

我的路由器是这样的:

App.Router.map(function() {
    this.route('login');
    this.resource('workspaces', function() {
      this.route('tasks', {path: ':slug'});
    }); 
});

在网上看了很多东西,但还没有完全弄明白。

谢谢。

最佳答案

:slug 是您的动态片段。您可以像这样访问 model Hook 中的动态段:

App.WorkspacesTasksRoute = Ember.Route.extend({
  model: function(param) {
    return { name: param.slug };
  }
});

查看工作 jsbin 示例 here

关于javascript - [EmberJS] : Get selected model in child template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28031175/

相关文章:

JavaScript - 改进URL参数获取算法

javascript - 从加载(isPending)闪烁到已解决。为什么?

javascript - 将 jQuery 与 Ember 操作处理程序一起使用

ember.js - 如何使用Ember.js的新路由器以编程方式在路由之间进行转换

javascript - 立即在 Ember.js 中渲染

ember.js 没有将 <label> For 属性{{bind Astr}} 到集合中正确的 inputField.elementId

javascript - AES-128-GCM 是否在 Node V6 上验证 IV?

javascript - Chrome 扩展 : IFrame and listening to clicks within it

javascript - 如何将动态价格推送到数据层?

javascript - Angular 路由器从根组件获取子参数