Id like to get the first returned value of data.countrys
model as below :
...el ...etc..
data: {
countrys: [
{KE : 'KENYA'},
{USA : 'USA'}
] ,
},
... ready...etc..
How can i get the value 'KE' in my method ? below is code am using in my method .
console.log(vm.$data.$children[0].countrys);
Id like to get the first returned value of data.countrys
model as below :
...el ...etc..
data: {
countrys: [
{KE : 'KENYA'},
{USA : 'USA'}
] ,
},
... ready...etc..
How can i get the value 'KE' in my method ? below is code am using in my method .
console.log(vm.$data.$children[0].countrys);
-
1
(Totally unrelated, but the plural of "country" is "countries".) You'd continue to write normal JS, reach into the
countries
array, and get the key. It's not as easy as it should be, e.g., each country could havename
andcode
keys, which would make it much simpler. – Dave Newton Commented Mar 1, 2016 at 14:37
2 Answers
Reset to default 2Since 'KE' is a key, you can use Object.keys function on the object within the 'countrys' array:
Object.keys(vm.data.countrys[0])[0];
vm.data.countrys[0] will return the {KE : 'KENYA'} object, and then Object.keys will return an array of keys of that object.
So... data
is object, countrys
- array of objects, then result is
var country = "KE";
data.countrys[0][country]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744156983a4560907.html
评论列表(0条)