admin管理员组文章数量:1287665
I am trying to use a bo box in Aurelia so that my users can type in a drop down and search the contents. I was trying to incorporate the one that Semantic had created, but when I call dropdown on the element it doesn't run the code, so it stays a normal dropdown. Like the state example here
.html
What's the best way to go about doing this, has anyone done this yet, or can think of a good way to implement this functionality?
I am trying to use a bo box in Aurelia so that my users can type in a drop down and search the contents. I was trying to incorporate the one that Semantic had created, but when I call dropdown on the element it doesn't run the code, so it stays a normal dropdown. Like the state example here
http://semantic-ui./modules/dropdown.html
What's the best way to go about doing this, has anyone done this yet, or can think of a good way to implement this functionality?
Share Improve this question edited Jul 30, 2015 at 22:48 dfsq 193k26 gold badges242 silver badges259 bronze badges asked Jul 30, 2015 at 18:32 Ashley SchuettAshley Schuett 1922 silver badges8 bronze badges 1- I've written a blog about creating custom elements for wrapping css frameworks here: davismj.me/blog/semantic-custom-element – Matthew James Davis Commented Aug 2, 2016 at 17:40
1 Answer
Reset to default 13First of all, install SemanticUI package. With JSPM run this line to install it from Github:
jspm install semantic-ui=github:Semantic-Org/Semantic-UI
It will also install jQuery as dependency. After that you will be able to import SemantinUI's jQuery plugins and styles into your view-model. View-model can be something like this then:
import {semanticUI} from 'semantic-ui';
import states from './states-list';
export class States {
constructor() {
this.states = states; // or load states with http-client, etc.
}
attached() {
$(this.statesSelect).dropdown().on('change', e => {
this.stateSelected = e.target.value;
});
}
}
and then you can render template with states list:
<template>
<p>Selected: ${stateSelected}</p>
<select ref="statesSelect" value.bind="stateSelected" class="ui search dropdown">
<option value="">State</option>
<option value="${state.code}"
model.bind="state.name"
repeat.for="state of states">${state.name}</option>
</select>
</template>
Couple of notes. You need to provide ref
attribute to reference HTMLElement from view-model, this way you don't have to hardcode CSS selectors into VM.
Also looks like Aurelia doesn't pick up proper value automatically after custom Semantic dropdown changes selection. In this case you can simply update model manually with onchange event.
Demo: http://plnkr.co/edit/vJcR7n?p=preview
本文标签: javascriptAurelia Semantic dropdownStack Overflow
版权声明:本文标题:javascript - Aurelia Semantic dropdown - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741249872a2365595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论