我是 Symfony2 的新开发人员,所以我很难将我从控制器中获得的对象数组转换为一个数组,其中包含我的树枝中的 JavaScript。
问题是我有一个数组数组:
这是一个例子
$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 之后