在Vue lifecycle hook中,我有以下AJAX呼叫
mSCA.setViewBinder(new SimpleCursorAdapter.ViewBinder(){
/** Binds the Cursor column defined by the specified index to the specified view */
public boolean setViewValue(View view,Cursor cursor,int columnIndex){
if(view.getId() == R.id.your_image_view_id){
String yourImageNameFromDb = cursor.getString(2);
int resID = getResources().getIdentifier(yourImageNameFromDb,"drawable",getPackageName());
((ImageView)view).setImageDrawable(getResources().getDrawable(resID));
return true; //true because the data was bound to the view
}
return false;
}
});
是否可以使用箭头函数来处理AJAX调用的结果?我尝试了以下
created: function () {
axios.get(`/list-suppliers/${this.newAwardNdc}`).then(function (response) {
this.supplierCount = _.uniqBy(response.data,'groupNumber').length;
}.bind(this));
}
但是它失败了,因为created: function () {
axios.get(`/list-suppliers/${this.newAwardNdc}`).then(response => {
this.supplierCount = _.uniqBy(response.data,'groupNumber').length;
});
}
没有正确绑定。