我是symfony2中的一個新開發者,所以我很痛苦轉換一個對象數組,我至少從我的樹枝中的js數組中獲得controlleur。錯過:在樹枝屬性編號後
的問題是,我有數組的數組:在樹枝
這裏的例子
$Flight = array
(
'1' => array
(
'5' => array
(
'LFID' => '6684',
'DepartureDate' => '2012-10-22T12:30:00',
'ArrivalDate' => '2012-10-22T14:00:00',
'BaseFareAmtInclTax' => '343.50',
'ReturnFlightSegmentDetails' =>
),
'10' => array
(
'LFID' => '6684',
'DepartureDate' => '2012-10-23T12:30:00',
'ArrivalDate' => '2012-10-23T14:00:00',
'BaseFareAmtInclTax' => '243.50',
'ReturnFlightSegmentDetails' =>
array
(
'150' => array
(
'LFID' => '6647',
'DepartureDate' => '2012-10-24T12:25:00',
'FareTypeName' => 'Change',
'FareTypeID' => '22',
'BaseFareAmtInclTax' => '198',
)
)
)
),
);
我做:
{% for flight in flights%}
var $FlightSegment = new Array();
$flight.push({
DepartureDate:"{{flight.DepartureDate}}",
ArrivalDate:"{{flight.ArrivalDate}}",
Amount:"{{flight.BaseFareAmtInclTax}}",
{% for ReturnFlightSegmentDetails in flight.ReturnFlightSegmentDetails %}
$FlightSegment.push({
ReturnFlightSegmentDetails :"{{ReturnFlightSegmentDetails.DepartureDate}}",
});
{% endfor %}
});
{% endfor %}
而行「$ FlightSegment .push「產生一個錯誤,這是」缺少:屬性ID後「
您編寫的代碼會爲每個航班重新聲明「$ FlightSegment」。然後,它會在您爲外部'.push()'調用構建的對象字面值內執行內部'.push()'調用*。 – Pointy