我正在使用jquery-ui-autocomplete,但是我的要求是使用逗号分隔多个值,我编写的代码仅适用于单个值,我尝试过这种方法,但是对于我来说这不起作用
Python 2.7.12,
jsonschema==3.0.1
attrs==19.1.0
six==1.12.0
pyrsistent==0.14.11
答案 0 :(得分:1)
只需对您的代码进行少量更改,然后对我来说就可以正常工作。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textSize="24sp"
android:textColor="@color/colorGreen"
android:textAlignment="inherit"/>
$( function() {
$( ".search_val" ).autocomplete({
source: function( request, response ) {
var searchText = extractLast(request.term);
$.ajax({
url: "<?php echo SITE_URL . 'ajax/get_users'; ?>",
type: 'get',
dataType: "json",
data: {
search: searchText
},
success: function( data ) {
response( data );
}
});
},focus: function() {
return false;
},
select: function( event, ui ) {
var terms = split( $('.search_val').val() );
terms.pop();
if(duplicate($('.search_val').val(), ui.item.label)){
terms.push( ui.item.label );
terms.push( "" );
$('.search_val').val(terms.join( ", " ));
}
return false;
}
});
});
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
function duplicate(f,s){
if( f.match(new RegExp("(?:^|,)"+s+"(?:,|$)"))) {
return false;
}else{
return true;
}
}
更改您的php代码
while($ row = mysqli_fetch_array($ result)){ $ response [] => array(“ value” => $ row ['userid'],“ label” => $ row ['username']); }
echo json_encode($ response);