我正在尝试获取 vaadin-combo-box 输入的值,但它返回[object Object]
。我不知道如何获取输入的实际值,我的表单将包含大约三个。请告诉我在读取 vaading-combo-box 的值时我做错了什么。
这是我的代码:
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<link rel="import" href="../bower_components/vaadin-combo-box/vaadin-combo-box.html">
<link rel="import" href="shared-styles.html">
<dom-module id="my-view2">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
</style>
<div class="card">
<iron-ajax
id="ajax"
url="http://localhost/data.php"
params=''
handle-as="text"
on-response="hresponse"
debounce-duration="300"></iron-ajax>
<paper-input label="Name" id="thename" name="thename"></paper-input>
<iron-ajax url="https://api.myjson.com/bins/1b0f7h" last-response="{{response}}" auto></iron-ajax>
<vaadin-combo-box name="fromm" id="fromm" items="[[response]]" item-value-path="fromm" label="fromm" item-label-path="countryName">
<template>
<paper-item-body two-line>
<div>[[item.countryName]]</div>
</paper-item-body>
</template>
</vaadin-combo-box>
<button on-click="setajax">Click me</button>
</div>
</template>
<script>
Polymer({
is: "my-view2",
setajax: function () {
alert(this.$.thename.value);
// alert(this.$.fromm.value); not working - returns Object object
// this.$.ajax.params = {thename:this.$.thename.value, fromm:this.$.fromm.value};
// this.$.ajax.generateRequest();
},
hresponse: function(request) {
console.log(request.detail.response);
console.log(this.$.ajax.lastResponse);
}
});
</script>
</dom-module>
我可以使用 alert(this.$.thename.value) 来提醒 Name 的值
,但是当我尝试对 from 的值做同样的事情时 alert(this.$. fromm.value)
它总是返回 [object Object]
。
最佳答案
您的 vaadin-combo-box
中的 item-value-path="fromm"
正在引用值为 response
对象的组合框。这就是为什么它向您显示[object Object]
。
将item-value-path
的值更改为您想要显示的值。
例如,如果您的对象类似于
响应:[{name:"stackoverflow",countryName:"澳大利亚"}]
如果要显示countryName的值,请输入item-value-path="countryName"
。
关于javascript - polymer ,vaadin-combo-box;获取输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46186771/