我的html形式带有vaadin-combo-box内部,该项目的值来自参考查询。我成功设置了选定的值以保存到主要数据中,但不幸的是,我仍然不知道如何设置第一个值onload
我只是尝试一下,但没有发现任何错误
html:
<form id="form">
<div>[[data.id]]<input size="1" name="id" value$='[[data.id]]'></div>
<div>
<iron-ajax url="url" last-response="{{response}}" auto></iron-ajax>
<vaadin-combo-box selected-item="{{No}}" placeholder="Please select" items=[[response]]" ></vaadin-combo-box>
</div>
</form>
JS:
ready(){
document.querySelectorAll('vaadin-combo-box').forEach(function(comboBox) {
document.querySelectorAll('vaadin-combo-box').value =
$(this.$.form).serializeJSON().regNo ;
});
}
尝试这样的东西。
document.querySelectorAll('vaadin-combo-box').forEach(function(comboBox) {
//write all the options in combo box as an array and assign it to comboBox.items
comboBox.items = ["a","b","C"]; //This is an example array.
comboBox.value = $(this.$.form).serializeJSON().regNo;
});
但是,如果您在Entier页面中只有一个" vaadin-combo-box",则
comboBox = document.querySelector('vaadin-combo-box')
//set all the options in combo box as an array and assign it to comboBox.items
comboBox.items = ["a","b","C"]; //This is an example array.
comboBox.value = $(this.$.form).serializeJSON().regNo;
有关更多详细信息,请检查https://vaadin.com/components/vaadin-combo-box/html-examples