您只需要将initiallyOpened
属性设置为true
.
此外,如果您想使用 jquery 打开电源选择。您可以在模板中调用 ember-power-select 并且可以在 component.js 中使用这些函数:
function touchToEmberPowerSelect(identifier) {
Ember.run(() => this.$('.' + identifier).get(0).dispatchEvent(new
MouseEvent('mousedown')));
}
仅供参考,以下代码可用于在打开下拉菜单后在代码中选择电源选择选项:
function createMouseEvent(){
let mouseevent = document.createEvent('MouseEvents');
mouseevent.initMouseEvent(
'mouseup',
true,
false,
window,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
return mouseevent;
}
function selectOptionWithDisplayTextOfEmberPowerSelect(identifier, displayText)
{
let matchedElements = $(".ember-power-select-option").filter(function() {
return ($(this).text().trim() === displayText);
});
if(matchedElements.length < 1){
Ember.assert("There is no element with display text");
}
else if(matchedElements.length > 1){
Ember.assert("There are more than one elements with display text");
}
Ember.run(() => matchedElements[0].dispatchEvent(createMouseEvent()));
}