简体   繁体   English

选择下拉值时获取[object,object]-代替表格

[英]getting [object, object] when dropdown value is selected - instead of table

I am coming to a problem where I have a dropdown with jsf tags and when I select a dropdown value - it shows [Object, object] . 我遇到的一个问题是,我有一个带有jsf标签的下拉列表,而当我选择一个下拉列表值时-它显示[Object, object] I try to convert from object to string using JSON.stringify(data); 我尝试使用JSON.stringify(data);从对象转换为字符串JSON.stringify(data); but it did not quite work. 但效果不佳。 Can anyone help me solve this issue. 谁能帮我解决这个问题。 I have a search input where the values show a html table - I want to do the same with my dropdown. 我有一个搜索输入,其中的值显示了html表-我想对下拉菜单进行相同的操作。 thanks for the help. 谢谢您的帮助。

Here is my code 这是我的代码

$('#sJobClass').on('change', function() {
  var jobClassCd = $(this).val(); 
  if (jobClassCd !== 0) {
    $.post('http://localhost:8080/myApp/JobSearchItem.xhtml',
           $('#searchForms').serialize(),
           function(data) {
             $('#results').append(data + '<br/><br/>');
             // $('#results').append($(text).find('table'));
             console.log(data);
             JSON.stringify(data);
           });

    $("#clearone").show();
  }
}); 

HTML with JSF tags 带有JSF标签的HTML

<select class="selectMenuSize" id="sJobClass" name="sJobClass">
  <option value="">choose</option>
  <c:forEach items="#{myBean.jobSearchItems}" var="searchItem">
    <option value="#{searchItem.getSearchValue()}" id="searchInputField"
            name="searchInput">#{searchItem.toString()}</option>
  </c:forEach>
</select>

Data 数据

{
  id: "11111",
  label: "PROGRAMMER (1111) ",
  value: "11111"
}

You appear to be calling JSON.stringify(data) (which is correct) but opting to ignore the result and instead use the raw value of data (which is not). 您似乎正在调用JSON.stringify(data) (这是正确的),但选择忽略结果,而是使用data的原始值(不是)。

Try this as your callback function: 尝试将此作为您的回调函数:

function(data) {
   $('#results').append(JSON.stringify(data) + '<br/><br/>');
});

you append all the return object and they have multiple attribution witch one you need to display in results ? 您附加所有返回对象,它们就有多个属性需要在结果中显示?

 $('#results').append(data.label + '<br/><br/>'); $('#results').append(data.id + data.label + '<br/><br/>'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dropDown时使用ng-change获取对象 - Getting the object selected with ng-change when dropDown 如何在下拉列表中显示带有所选值的 object - How to display object with the selected value in dropdown Angular4-获取“未定义”而不是下拉所选值 - Angular4 - Getting “undefined” instead of dropdown selected value 在表中使用xpath进行遍历时,量角器将返回对象而不是值 - Protractor is returning the object instead of the value when traversing using xpath in table 选择下拉菜单中的值时,如何在文本字段中显示对象的相应值 - How to show the corresponding value of an object in a text field when a value from a dropdown is selected 下拉列表显示[对象对象]而不是使用剔除的值 - Dropdown list display [object object] instead of value using knockout 获取对象对象,而不是通过json对象“读取”值 - Getting object Object instead of value “reading” through json object 从表格单元格内的下拉列表中获取所选值 - Getting selected value from, dropdown list placed inside table cell 为什么在使用Spidermonkey时输出为[object Object]而不是[Id:id_value] - Why am i getting output as [object Object] instead of [Id: id_value] when using Spidermonkey 为获取对象属性标识符而不是属性值? - For in getting object property identifier instead of property value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM