【问题标题】:Ember-Power-Select: Check if something is selected?Ember-Power-Select:检查是否选择了某些东西?
【发布时间】:2017-03-20 14:37:07
【问题描述】:

如果 ember-power-select 有一个值/选择了什么,我如何检查 Ember?

编辑: 我已经有了 onchange=(action (mut selection))。 但我有一个计算属性,它监听“选择”。 当我第一次访问该站点(url 或重新加载)时,将根据 model.name 填充选择。该值显示在 power select 中,但未调用计算属性

【问题讨论】:

  • selection will be filled based on model.name - 你在哪里设置这个发生?请包含该代码
  • 嘿,我犯了一个错误。计算的属性只听'selection',但我必须听'selection.name',因为它是一个模型

标签: select ember.js


【解决方案1】:

浏览很棒的文档http://www.ember-power-select.com/docs/action-handling。实际上它遵循 DataDownActionsUp 原则,更改将通过动作来传达。

你需要定义onchange动作

{{#power-select
  selected=destination
  options=cities
  onchange=(action "chooseDestination")
  as |name|
}}
  {{name}}
{{/power-select}}

在对应的地方实现逻辑,

import Ember from 'ember';
export default Ember.Controller.extend({
  cities: ['Barcelona', 'London', 'New York', 'Porto'],
  destination: 'London',

  actions: {
    chooseDestination(city) {
      this.set('destination', city);
      // this.calculateRoute();
      // this.updatePrice();
    }
  }
});

如果你只想单独更新selected属性,那么你可以简单地说onchange=(action (mut destination))

【讨论】:

  • 是的,我知道,抱歉需要更多描述。请看我的编辑
猜你喜欢
  • 2012-06-04
  • 2011-06-06
  • 2014-05-12
  • 1970-01-01
  • 2012-05-11
  • 2012-03-12
  • 1970-01-01
相关资源
最近更新 更多