3
我正在使用jQuery來實現我需要的功能,但是在我的代碼中有一部分是我認爲可以改進的,但我沒有想法,我有一個json調用,並且正在存儲該數據在可變在jQuery上正確使用地圖
var getData = localStorage.getItem('jsonData');
該變量有這個值
[
{
"enterprise" : [
{
"id" : "10",
"name" : "Hellen Quesada",
"role" : "Principal Software Engineer",
"picture" : "http://i276.photobucket.com/albums/kk35/Sicable/200x200/06.png",
"skype" : "skypeusername",
"email" : "[email protected]",
"account" : "digitas, flag",
"subDept" : "enterprise",
"location" : "Offshose: Costa Rica"
},
{
"id" : "11",
"name" : "Jonathan Chavez",
"role" : "Principal Creative Engineer",
"picture" : "http://i276.photobucket.com/albums/kk35/Sicable/200x200/06.png",
"skype" : "skypeusername",
"email" : "[email protected]",
"account" : "digitas, flag",
"subDept" : "enterprise",
"location" : "Offshose: Costa Rica"
},
{
"id" : "12",
"name" : "Rodrigo Ovares",
"role" : "Creative Engineer",
"picture" : "http://i276.photobucket.com/albums/kk35/Sicable/200x200/06.png",
"skype" : "skypeusername",
"email" : "[email protected]",
"account" : "digitas, flag",
"subDept" : "enterprise",
"location" : "Offshose: Costa Rica"
},
{
"id" : "13",
"name" : "Juan Morera",
"role" : "Software Engineer",
"picture" : "http://i276.photobucket.com/albums/kk35/Sicable/200x200/06.png",
"skype" : "skypeusername",
"email" : "[email protected]",
"account" : "digitas, flag",
"subDept" : "enterprise",
"location" : "Offshose: Costa Rica"
}
]
}
]
而且我遍歷這個JSON這樣才能達到,直到id
屬性進行DOM中的渲染localStorage的
$.map(JSON.parse(getData), function(items) {
$.map(items, function(item) {
$.map(item, function(data) {
if (id === data.id) {
loading = true;
if (loading) {
$('.spinner').css('display', 'block');
setTimeout(function() {
$('.spinner').css('display', 'none');
cardTemplate.push('<li><span class="name-role" id="name">' +
'<span><img class="card-picture" src="'+ data.picture +'"/></span>' +
'<div class="main-info-card">' +
data.name + '<br>' +
data.role + '<br>' +
'Employee N.' + data.id +
'</div>' +
'</span></li>' +
'<li><p>Email: <strong>'+ data.email +'</strong></p></li>' +
'<li><p>Skype: <strong>'+ data.skype +'</strong></p></li>' +
'<li><p class="team"> '+ data.account +' <br> <strong>Enterprise</strong></p></li>' +
'<li><strong> '+ data.location +'</strong></li>');
$('<ul/>', {
"class" : "removeLi",
html: cardTemplate.join('')
}).prependTo('.personal-info');
var rem = $('.removeLi');
removeEl.push(rem);
if (rem.length > 1) {
rem.first().next().remove();
}
}, 1000);
}
} // if ends
});
});
});
正如你有看到我有3個$.map
S和那就是我想知道是否有改善的那部分的方式,到目前爲止,這3個$.map
s的做什麼我需要什麼,但我認爲重複$.map
可能會帶來一些性能問題。
你有什麼建議?