Javascript 聚合物中的绑定语义UI下拉列表
我目前正在绑定数据,但我现在想使用下拉列表。我想要这样的东西:Javascript 聚合物中的绑定语义UI下拉列表,javascript,polymer,polymer-1.0,semantic-ui,Javascript,Polymer,Polymer 1.0,Semantic Ui,我目前正在绑定数据,但我现在想使用下拉列表。我想要这样的东西: // inside a dom-module template <select value="{{selection}}" class="ui dropdown" id="select"> <option value="a">Alpha A</option> <option value="b">Alpha B</option> <option value="c"
// inside a dom-module template
<select value="{{selection}}" class="ui dropdown" id="select">
<option value="a">Alpha A</option>
<option value="b">Alpha B</option>
<option value="c">Alpha D</option>
</select>
<script>
$('#select').dropdown();
</script>
Polymer({
is: 'my-app',
selectionChanged: function() {
if (this.selection === 'c') {
alert('Teen Wolf');
}
}
});
如何在?中获取所选选项不幸的是,我还没有成功地使用带有双向数据绑定的语义UI。我目前使用的唯一方法是自己进行绑定 初始化下拉列表时,可以绑定到onChange事件:
$('#select').dropdown({
onChange: function(value, text, $choice) {
this.selected = value;
}.bind(this)
});
如果需要,您还可以修改selectionChanged函数以设置下拉列表,以防需要从其他位置设置选择值。但不确定是否需要针对事件循环进行保护:
selectionChanged: function(oldValue, newValue) {
// Just in case, check the dropdown value before setting it
if ($('#select').dropdown('get value') !== this.selection)
$('#select').dropdown('set value', newValue);
// Continue doing other stuff with your selection value here
// ...
// ...
}
不幸的是,我还没有设法让Polymer使用带有双向数据绑定的语义UI。我目前使用的唯一方法是自己进行绑定 初始化下拉列表时,可以绑定到onChange事件:
$('#select').dropdown({
onChange: function(value, text, $choice) {
this.selected = value;
}.bind(this)
});
如果需要,您还可以修改selectionChanged函数以设置下拉列表,以防需要从其他位置设置选择值。但不确定是否需要针对事件循环进行保护:
selectionChanged: function(oldValue, newValue) {
// Just in case, check the dropdown value before setting it
if ($('#select').dropdown('get value') !== this.selection)
$('#select').dropdown('set value', newValue);
// Continue doing other stuff with your selection value here
// ...
// ...
}
我确实试过了,但没有效果。我想我们不能像在控制台中那样绑定这种类型的下拉列表,我看不到值集为nothing。如果使用样式实例化和隐藏输入,而不是使用元素,则可以绑定select元素。您的配置中有JSFIDLE设置吗?这将是帮助你摆脱困境的理想选择。我确实尝试过,但没有任何效果。我想我们不能像在控制台中那样绑定这种类型的下拉列表,我看不到值集为nothing。如果使用样式实例化和隐藏输入,而不是使用元素,则可以绑定select元素。您的配置中有JSFIDLE设置吗?这将是帮助你走出困境的理想选择。