如何使用Ember以编程方式选择下拉选项? [英] How can I programatically select a drop down option using Ember?

查看:54
本文介绍了如何使用Ember以编程方式选择下拉选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的示例下拉列表

<select name="newType" class="parts-select full-width-combo" onchange={{action "loadFilter" value="target.value" }}>
            <option value="" selected  hidden >Select </option>
            {{#each model as |item|}}
                <option value="{{item.id}}">{{item.description}}</option>
            {{/each}}
 </select>

从相关模板操作中,我想动态设置此选定项。

from the relevant template action I wanted to set this selected item dynamically.

作为示例,默认情况下它是由选择选择的,然后基于该页面上的某个按钮单击,并且需要将我的所选选项设置为要选择的其他所选选项。
我没有使用任何插件,我在这里不能做。

As an example it default selected by "Select" and then based on some button click on that page and need to set my selected option to other selected option to be selected. I am not using any plugin and I can't do it here.

推荐答案

您可以使用 ember-truth-helpers ' eq helper设置选择哪个选项。我相信我已经在这个话题。请参阅 my-component.hbs 了解如何使用 eq 助手来设置 selected 属性。

You can use ember-truth-helpers' eq helper to set which option is selected. I believe I have coded what you are asking at this twiddle. See my-component.hbs about how I used eq helper to set selected attributes of each option.

我建议使用 ember- power-select 选择框,而不是尝试使用选项编写自己的选择。

By the way I suggest using ember-power-select for select box instead of trying to write your own select with options.

这篇关于如何使用Ember以编程方式选择下拉选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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