this
がjquery .each()
ループの場合、次のjavascriptオブジェクトからthis
(特定の 'イベント')を削除できません。jQuery .each()のjavascriptオブジェクトからこれを削除します
weatherData:
{
"events":{
"Birthday":{
"type":"Annual",
"date":"20120523",
"weatherType":"clouds",
"high":"40",
"low":"30",
"speed":"15",
"direction":"0",
"humidity":"0"
},
"Move Out Day":{
"type":"One Time",
"date":"20120601",
"weatherType":"storm",
"high":"80",
"low":"76",
"speed":"15",
"direction":"56",
"humidity":"100"
}
},
"dates":{
"default":{
"type":"clouds",
"high":"40",
"low":"30",
"speed":"15",
"direction":"0",
"humidity":"0"
},
"20120521":{
"type":"clear",
"high":"60",
"low":"55",
"speed":"10",
"direction":"56",
"humidity":"25"
}
}
}
これは.each()
ループの収縮したバージョンです:
$.each(weatherData.events, function(i){
if(this.type == "One Time"){
delete weatherData.events[this];
}
})
あなたは単にweatherData.eventsを空に良いかもしれない(weatherData.events = {})、それを削除しようとするのではなく。私が最近聞いたインタビューのv8作者の一人によると、オブジェクトのメンバを削除すると、そのオブジェクトはハッシュに変換された後、オブジェクトに戻されますが、オブジェクト内の再割り当てにはobject-> hash - >オブジェクトパフォーマンスのペナルティ。 – BrianFreud
それは良いアドバイスのように聞こえる。もし私がその内容のいくつかを保存しようとしていなければ、私はそれをするでしょう。私は特定の出来事だけを削除していました。私は私のポストをオープニングの説明でより具体的に更新する予定です。 – fishpen0