【问题标题】:set first value on vaadin-combo-box在 vaadin-combo-box 上设置第一个值
【发布时间】:2019-05-24 03:55:53
【问题描述】:

我有一个带有 vaadin-combo-box 的 HTML 表单,该项目的值来自参考查询。我成功设置选定的值以保存到主数据中,但不幸的是,我仍然不知道如何设置第一个值 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 ;
  });
}

【问题讨论】:

    标签: javascript polymer vaadin


    【解决方案1】:

    试试这样的。

    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;
    });
    

    但是,如果您的整个页面中只有一个“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

    【讨论】:

    • 仍然不起作用@murali,但我刚刚找到了如下解决方案: .. 感谢您的回复
    • 很高兴听到您找到了解决方案。我可以知道是什么问题。
    • 只加值$='[[data.No]]'
    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 2019-10-13
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多