【发布时间】:2018-06-04 20:03:43
【问题描述】:
代码:
$.ajax({
url : '/Addbus',
type : 'POST',
dataType : 'JSON',
success : function(data){
var dt = JSON.parse(data.body);
$.each(dt,function(i,v){
$.each(v,function(j,p){
var arr={};
arr= p.name+ ',' +p.id;
temp.push(arr);
var result=JSON.stringify(temp);
console.log(result);
$("#source").autocomplete({
source: result, // The source of the AJAX results
minLength: 3, // The minimum amount of characters that must be typed before the autocomplete is triggered
focus: function( event, ui ) { // What happens when an autocomplete result is focused on
$("#source").val( ui.item.value );
return false;
},
select: function ( event, ui ) { // What happens when an autocomplete result is selected
$("#source").val( ui.item.value );
$('#source-id').val( ui.item.label );
}
});
当我在文本框中选择 cityname 然后在 ui.item.value 和 ui.item.label 我得到的值是
物品
:
标签
:
“海得拉巴,6”
价值
:
“海得拉巴,6”,
现在我怎样才能将它们分开并接受不同的值。例如我想要值作为 id=6 和 name=hyderabad。
【问题讨论】:
-
你会得到像
, 这样的值,所以你可以用逗号分割它
标签: javascript jquery arrays node.js mongodb