1
我想从我的回调函数中获取联系人值。如何从回调函数中获取变量的值?
如何让我的this.recherche = contacts
?
App.provider('ContactsP', function() {
this.$get = function() {
return function(search) {
console.log('Factory ContactsCtrl RECHERCHE : ' + search);
this.recherche = [];
this.options = new ContactFindOptions();
this.options.filter = search;
this.options.multiple = true;
this.fields = ["displayName", "name", "phoneNumbers"];
navigator.contacts.find(this.fields, function(contacts) {
//I want to put contacts into this.recherche but that doesn't work....
this.recherche = contacts; return contacts;
}, function(e) {
console.log("Error finding contacts " + e.code)
}, this.options);
};
};
您使用的是什么JavaScript库? –
我不会工作,因为'这'是另一个背景。你可以将'this'存储在一个变量中并在回调中使用。 – Luketep
它看起来像'.find'我是一个异步功能。在这种情况下,请看[如何从AJAX调用返回响应?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call )。 –