mercredi 15 avril 2015

How to code Router path dynamic segment so Model attribute is not 'undefined'?

In a CLI-based Ember app, using cli-api-stub to serve static test JSON, I have a Route 'search' action which gets and sets hotel reservation JSON data on 'controller.model'. A View loops the items with '{{#each item in model itemController="reservations/-item"}}', and the reservation item gets passed to a 'modifyReservation' action with '{{action "modifyReservation" item}}'. This action then passes the reservation to 'this.transitionTo('find-booking.summary', reservation)' where the reservation ID should appear as a dynamic segment, but I'm getting 'undefined' for it (../find-booking/undefined).


The JSON:



"ResGlobalInfo": {
"HotelReservationIDs": {
"HotelReservationID": [
{
"@ResID_Value": "HG34A2"


In ../app/router.js:



this.route('summary', {path: "/:ResGlobalInfo.HotelReservationIDs.HotelReservationID.firstObject.@ResID_Value"}, function(){


In the action function, I can console out the ID with (reservation.ResGlobalInfo.HotelReservationIDs.HotelReservationID[0]['@ResID_Value']), but with (reservation.ResGlobalInfo.HotelReservationIDs.HotelReservationID.firstObject.@ResID_Value) I get a broccoli build error. It doesn't seem to like the '@'. Of course with this accessor/path as a dynamic segment path I also get 'undefined'. I've tried a few syntax variations and none of them work.


How can I code my router path dynamic segement so it pulls the reservation ID 'attrib' from the JSON object passed to the Route?


Aucun commentaire:

Enregistrer un commentaire