Search code examples
ember.jsember-datahandlebars.js

No longer able to bind to global data structures in Ember?


I've been using some Ember objects in my code, such as "App.SelectedBlock" to access selected items in lists (a practice that started when I was using Sproutcore years ago) and now it looks like binding to these objects from the Handlebars templates is going to be deprecated and I'm not sure how to go about fixing that. I'm running Ember 1.8.1 and right now it will still work but I'll get "DEPRECATION: Global lookup of App.SelectedBlock from a Handlebars template is deprecated." and I'm pretty sure it's full removed in 1.9.0. I'm not sure how to go about fixing this without having to completely restructure my code. Any suggestions?


Solution

  • I guess you're doing smthing like:

    {{App.SelectedBlock.id}}
    

    You should not call global variables inside Handlebars template. This is a bad practice. But you can do smthing like this:

    // in your template controller
    selectedBlock: function(){
      return Ember.get('App.SelectedBlock');
    }.property('App.SelectedBlock')
    

    In hbs template:

    {{selectedBlock.id}}