私は Javascript が初めてで、document.getElementById を使用してアイテムの値を表示したいと考えています。私の例では、var= btsFrontEnd に出力された名前をリストしたいと思いますが、何か間違っています。どんな助けでも大歓迎です。
ありがとうございました。 私のフィドルへのリンク
var btsFrontEnd = {
"employee-1": {
"name": "Name One",
"phone": "1234567890",
"email": "blah@blah.com"
},
"employee-2": {
"name": "Name Two",
"phone": "1234567890",
"email": "blah@blah."
}
};
var btsemployees = {
employees:[
{
"name": "Name One",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Two",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Three",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Four",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Five",
"phone": "1234567890",
"email": "blah@blah.com"
}
]
};
//First argument is our data structure (an object or an array
//Second argument is a callback (logic we apply to our data structure)
$.each(btsFrontEnd, function (key, value) {
console.log(key); //Prints this object's keys
console.log(value); //Prints immediate values from this object
console.log(btsFrontEnd[key]);
console.log(value.name);
document.getElementById("names").innerHTML.value;// This is what I am referring to, I would like it to appear in the p id="names"
});