【问题标题】:Issue with ember-power-select, wrong display, but good dataember-power-select 出现问题,显示错误,但数据良好
【发布时间】:2017-08-10 14:51:21
【问题描述】:


我对 ember-power-select 有一个小问题。在表单中,我想将值设置为 LogicalPhysical,因此我决定使用 ember-power-select。它工作正常,但是当我使用 ember-power-select 更改表单上的值时,显示仍然相同,我的意思是我停留在 Logical 上,即使该值为 物理。
这是模板:

{{#form.element label=(t 'type')}}
  {{#power-select
    selected=selectedType
    searchEnabled=false
    options=allType
    onchange=(action (mut zone.type))
    placeholder=(t 'type_zone')
    as |type|}}
  {{/power-select}}
{{/form.element}}

这是组件:

allType: ['Logical', 'Physical'],
selectedType: 'Logical'

还有模特:

type: DS.attr('string')

与此电源选择相关的所有内容都在这里。

【问题讨论】:

    标签: ember.js ember-data display


    【解决方案1】:

    selected=selected 将其更改为 selected=selectedType

    您需要提供selectedType 来维护选定的属性。


    试试这个,我们删除了selectedType 并使用zone.type 作为选定类型。

    selected=zone.typeonchange=(action (mut zone.type)) 这里onchange 操作会将选定的值设置为zone.type。所以你需要 selected=zone.type 只有这样选定的更改才会持续存在。

    【讨论】:

    • 是的,我也试过了,但是电源选择保持在 Logical 上。如果我不触摸任何东西,type 的值是未定义的,如果我点击Physical,值会变为physical,但显示仍然显示Logical。而且我无法将值更改为 Logical
    • 如果我把onchange(action (mut zone.type))改成(action (mut selectedType)),显示效果很好,但是zone.type的值当然是未定义的。
    • 感谢您的完美工作,应该早点尝试!
    猜你喜欢
    • 2020-11-24
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多