![](/img/trans.png)
[英]How to get an input element that has an array name which I have assigned the value of the index?
[英]How to get the array element value which has no name in AngularJS
在AngularJS控制器中,我有一個名為contact的關聯數組。 我必須獲取沒有名稱的數組的元素。 在這里,我已經發布了我的代碼和回復,供您參考
這是我的控制器代碼
function onSuccess(contacts) {
console.log(contacts);
for (var i = 0; i < contacts.length; i++) {
var list = contacts[i].phoneNumbers;
console.log(list);
}
}
這是我的contacts
數組
[Contact, Contact, Contact, Contact, Contact, Contact, Contact, Contact]
0:Contact
addresses:null
birthday:Invalid Date
categories:null
displayName:"UIDAI"
emails:null
id:"16"
ims:null
name:Object
nickname:null
note:null
organizations:null
phoneNumbers:Array[1]
0:Object
id:"109"
pref:false
type:"other"
value:"1800-300-1947"
__proto_:Object
length:1
__proto_:Array[0]
photos:null
rawId:"17"
urls:null
__proto__:Object
1:Contact
addresses:null
birthday:Invalid Date
categories:null
displayName:"Distress Number"
emails:null
id:"17"
ims: null
name:Object
nickname: null
note:null
organizations:null
phoneNumbers:Array[1]
0:Object
length:1
__proto__:Array[0]
photos:null
rawId :"16"
urls:null
__proto__:Object
這是console.log(list)數組的日志
Array[8]
0:Array[1]
0:Object
id:"109"
pref:false
type:"other"
value:"1800-300-1947"
在這里,我必須從中獲取元素value
。
這里phoneNumbers
是一個數組。
因此,您需要以contacts[i].phoneNumbers[0].value
身份對其進行訪問
您也可以使用lodash實用程序僅從通訊錄數組中獲取電話號碼列表。 -僅供參考
list.value
將為您提供價值
function onSuccess(contacts) {
console.log(contacts);
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].phoneNumbers){
var list = contacts[i].phoneNumbers;
var value = list.value;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.