返回值为undefined

this指向性问题

var that=this

使用that即可

getContacts:function(){
	let list=[]
	var that=this
	//获取通讯录对象
	plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {
			addressbook.find(["displayName","phoneNumbers"],function(contacts){
				// uni.showToast({
				// 	title: '获取联系人成功',
				// 	duration: 2000
				// })
				console.log(contacts)
				// console.log(JSON.stringify(contacts))
				that.clist = contacts
				contacts.forEach((item) => {
					item.phoneNumbers.forEach((t,k) => {
						if(t.value != ''){
							let a={
								"displayName":item.displayName,
								"phoneNumbers":t.value
							}
							that.contactslist.push(a)
							that.cleanContacts()
						}
					})
				})
			}, function () {
				uni.showToast({
					title: '获取联系人失败',
					duration: 2000
				})
			},{multiple:true});
		}, function ( e ) {
			uni.showToast({
				title: '获取通讯录对象失败:' + e.message,
				duration: 2000
			})
		});
		
},
cleanContacts:function(){
	console.log(this.contactslist)
}
//getContacts方法中contacts
[{
	"id": 1,
	"rawId": null,
	"target": 0,
	"displayName": "姓名",
	"name": null,
	"nickname": null,
	"phoneNumbers": [{
		"id": 0,
		"pref": false,
		"type": "mobile",
		"value": "150 0000 1111"
	}],
	"emails": null,
	"addresses": null,
	"ims": null,
	"organizations": null,
	"birthday": null,
	"note": null,
	"photos": null,
	"categories": null,
	"urls": null
}]


//contactslist----用于存放需要的数据
[{
	"displayName": "姓名",
	"phoneNumbers": "150 0000 1111"
}]

更多推荐