[英]Javascript add arrays to array object - problem pushing always the same value
[英]Javascript Array not pushing when having the same same value to object
對象忽略具有相同值的其他數組。 例如
data[2018][2][25] <-- this ones gets ignored to the object
data[2018][2][22]
代碼:
var date = new Date();
var data = {};
<?php $eventsNum = 3>
<?php for ($r =1; $r <= 3; $r++):?>
data[<?php echo $calendarYear[$r]?>] = {};
<?php for ($s =1; $s <= 3; $s++):?>
data[<?php echo $calendarYear[$r]?>][<?php echo $calendarMonth[$s]?>] = {};
<?php for ($t =1; $t <= 2; $t++):?>
data[<?php echo $calendarYear[$r]?>][<?php echo $calendarMonth[$s]?>][<?php echo $calendarDay[$s] ?>] = {};
//$num = $calendarDay[$s];
try {
data[<?php echo $calendarYear[$r]?>][<?php echo $calendarMonth[$s]?>][<?php echo $calendarDay[$s] ?>].push({
startTime: "<?php echo $calendarStart_time[1]?>",
endTime: "<?php echo $calendarEnd_time[1] ?>",
text: "<?php echo $calendar_description[1] ?>"
問題是每次通過循環時,您都會完全替換該屬性中的現有對象。 改變:
data[<?php echo $calendarYear[$r]?>] = {};
到:
if (!data[<?php echo $calendarYear[$r]?>]) {
data[<?php echo $calendarYear[$r]?>] = {};
}
和所有其他初始化類似。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.