$Flight = array
(
'1' => array
(
'5' => array
(
'LFID' => '6684',
'DepartureDate' => '2012-10-22T12:30:00',
'ArrivalDate' => '2012-10-22T14:00:00',
'BaseFareAmtInclTax' => '343.50',
'ReturnFlightSegmentDetails' =>
array
(
'87' => array
(
'LFID' => '6647',
'DepartureDate' => '2012-10-24T12:25:00',
'FareTypeName' => 'Change',
'FareTypeID' => '22',
'BaseFareAmtInclTax' => '198',
)
)
),
'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',
),
'153' => Array
(
'LFID' => '6647',
'DepartureDate' => '2012-10-26T12:25:00',
'FareTypeName' => 'Change',
'FareTypeID' => '22',
'BaseFareAmtInclTax' => '198',
)
)
)
),
);
我從控制器至極這個數組傳遞給我的樹枝在那裏我執行下面的代碼,它解析爲一個JS數組:推在爵士看不到風度的陣列正常工作
{% for flight in flights%}
var $FlightSegment = new Array();
$flight.push({
key:"{{ flight.key }}",
DepartureDate:"{{flight.DepartureDate}}",
ArrivalDate:"{{flight.ArrivalDate}}",
Amount:"{{flight.BaseFareAmtInclTax}}",
});
{% for ReturnFlightSegmentDetails in flight.ReturnFlightSegmentDetails %}
$FlightSegment.push({
LFID :"{{ReturnFlightSegmentDetails.LFID}}",
DepartureDate:"{{ReturnFlightSegmentDetails.DepartureDate}}",
ArrivalDate:"{{ReturnFlightSegmentDetails.BaseFareAmtInclTax}}",
Class:"{{ReturnFlightSegmentDetails.FareTypeName}}",
});
{% endfor %}
console.info($FlightSegment);
$flight.push({
ReturnFlightSegmentDetails :$FlightSegment,
});
{% endfor %}
問題是,$ flight.length返回4而不是2:/的ReturnFlightSegmentDetails被認爲是像一個對象,而不是成爲一個飛行中的attibut:/
那麼你是單獨推入清單。 – Pointy
此外,建議讓小枝用'json_encode'做這件事似乎是一個不錯的主意。 – Pointy
對不起,但我不明白哪裏是錯誤:/我在全球範圍內第二次推! oO'我將排序數據,所以這就是爲什麼我選擇解析到一個js數組,因爲它會更容易,我想然後有一個字符串與json_encode – fbh