ember.js - How to ensure the same controller instance is referenced in two different places in ember -


tl;dr: ember creating 2 instances of arraycontroller when want one. how ensure code referencing same one?

the scenario

using ember, trying create section of page potential buyers can select 2 sets of options, click button accept options , redirect page based on choices. example:

enter image description here

however, when click button, uses whatever selected when page first loaded, ignoring actions in between.

let's work through code

when click reserve button, triggers action on lessonpackagescontroller:

#handlebars template <a {{action booklesson on="click"}}>reserve now</a> 

here's action triggers: (if don't understand emberscript, imagine it's pseudocode... runs)

#lessonpackagescontroller booklesson: ->   window.location = @bookingurl 

the location points outside ember application, don't think transitiontoroute , sibling methods viable.

@bookingurl computed property on controller.

#lessonpackagescontroller +computed chosenpackage lessontype bookingurl: ->   url = "/instructors/#{@id}/lesson_bookings/new"   url += "/#{@lessontype}"   url += "/#{@chosenpackage.name}" if @chosenpackage   url 

to simplify, i've started out setting @lessontype default ('private'), , don't have worry how @id being fetched, because it's working.

before details of how @chosenpackage updated, put code logs every time @chosenpackage updated, confirming both @chosenpackage , @bookingurl being updated expected.

#lessonpackagescontroller +observer chosenpackage yolo: ->   console.log(@bookingurl) 

whenever click lesson package, example six-lesson package, see following in console: /instructors/58/lesson_bookings/new/private/six. expected.

however, when click reserve button, following: /instructors/58/lesson_bookings/new/private. @bookingurl exists before @chosenpackage updated.

the plot thickens

in further tests, put @content log in 'yolo', , found content was... empty array. putting null @chosenpackage in @booklesson, surmised accessing 2 different instances of lessonpackagescontroller. here's how access when updating @chosenpackage (which triggers @yolo function):

class app.lessonpackagecontroller extends ember.objectcontroller   needs: ['lessonpackages']   selectme: ->     @chosenpackage =    +computed chosenpackage   chosen: ->     == @chosenpackage    chosenpackagebinding: 'controllers.lessonpackages.chosenpackage'   chosenpackage: '' 

i know lessonpackagecontroller instances interact same lessonpackagescontroller because selecting 1 deselect current chosen package. however, happens different instance @booklesson called on.

how ensure 2 instances in fact 1 instance, same instance?


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -