我尝试在JavaScript的帮助下在输入字段中创建标记,并尝试向用户建议数据库中的自动完成建议。
我可以使用简单的JavaScript创建标签但我无法获取已创建的标签并将其传递给JavaScript函数以进行自动完成建议。
输入字段
FirebaseRecyclerAdapter<Post, FirebaseViewHolder> adapter = new FirebaseRecyclerAdapter<Post, FirebaseViewHolder>(
Post.class,
R.layout.recyclerview_list_item,
FirebaseViewHolder.class,
databaseReference
) {
@Override
protected void populateViewHolder(FirebaseViewHolder viewHolder, Post model, int position) {
Picasso.with(getActivity())
.load(model.image_url)
.into(viewHolder.mImageView);
Log.v(TAG, model.image_url);
//viewHolder.mImageView.setImageResource(R.mipmap.ic_launcher);
viewHolder.mPostTitle.setText(model.title);
viewHolder.mPostDesc.setText(model.desc);
}
@Override
public FirebaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
FirebaseViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
viewHolder.setOnClickListener(new FirebaseViewHolder.ClickListener() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(getActivity(), "Item clicked at " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onItemLongClick(View view, int position) {
Toast.makeText(getActivity(), "Item long clicked at " + position, Toast.LENGTH_SHORT).show();
}
});
return viewHolder;
}
};
JavaScript功能
<input type="text" name="area_token" id="area_token">
这里我想要的是传递查询数据库并将其传递给该自动填充功能中的数据。
我编写了一个AJAX函数来从数据库中获取数据
$(function() {
$("#area_token").tags({
}).autofill({
data:["java-script","MySQL","ajax","Python"]
});
});
我在这里做错了什么,或者我怎样才能实现它?
答案 0 :(得分:0)
如果你的AJAX请求背后的功能没问题,那么你只需要这个“改变”
function display_detail_of_follow_up_meetings(studentid) {
$.ajax({
type: "POST",
dataType:'json',
url: base_path+"admission_inquiry/display_inquiry_meetings_byinquiryid_json",
data:({
'inquiry_id':studentid
}),
beforeSend:function() {
overlay_ajax();
},
success:function(data) {
// here is your MySQL result named "data"
$("#area_token").tags({ }).autofill({
data: data // and here you pass your data from AJAX
});
},
error:function(){
alert('ajax call failed...');
},
complete: function(){
$.unblockUI();
}
});
}