您好我有一个md自动完成搜索框,我的问题是在输入名称时会调用搜索功能。搜索函数调用api,但同时它将null数组返回到自动完成表单。有没有办法告诉函数不返回任何东西,并在找到后找回答案后回复?另外,在等待这些结果的同时,使md auto complete显示加载文本或图像?请找到以下代码:
CODE: html -
DatabaseReference dref;
ListView listview;
ArrayList<String> list=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview=(ListView)findViewById(R.id.listview);
final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,list);
listview.setAdapter(adapter);
dref=FirebaseDatabase.getInstance().getReference();
dref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
list.add(dataSnapshot.getValue(String.class));
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
list.remove(dataSnapshot.getValue(String.class));
adapter.notifyDataSetChanged();
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
JS -
<md-autocomplete md-selected-item="selectedLocation" md-selected-item-change="selectLocation(item)" md-search-text="searchText"
md-items="item in searchLocations(searchText)" md-item-text="item.Name" md-min-length="3" placeholder="search location" md-select-on-match="true"
md-match-case-insensitive="true" md-no-cache="true">
<md-item-template>
<span md-highlight-text="searchText">{{item.id}}</span>
</md-item-template>
<md-not-found>
No results found.
</md-not-found>
</md-autocomplete>
答案 0 :(得分:0)
我终于想到了这个问题。万一有人碰到这个,你可以做一个承诺,并确保你回报承诺!在我的情况下,我做了:
return Location.query(params).$promise.then(
function(data){
return data;
}
);