Bindings on ObjectController - Ember.js

后端 未结 2 748
遇见更好的自我
遇见更好的自我 2021-02-19 12:56

When you try adding a binding to an ObjectController it doesn\'t work.

App.FailController = Em.ObjectController.extend({
    content: null,
    myBi         


        
相关标签:
2条回答
  • 2021-02-19 13:25

    Alternative solution:

    App.FailController = Em.ObjectController.extend({
        content: Ember.Object.create(),
        my: function() {
          return App.router.myController;
        }.property('App.router.myController')
    });
    

    or better:

    App.FailController = Em.ObjectController.extend({
        content: Ember.Object.create(),
        my: Ember.computed.alias('App.router.myController')
    });
    
    0 讨论(0)
  • 2021-02-19 13:31

    credits: to caligo-mentis who answered this over at github.

    ObjectProxy delegates any call to set to the content property unless a property with the same name exists on the ObjectProxy instance. The simple solution is to define a property with the desired name prior to declaring the binding.

    App.FailController = Em.ObjectController.extend({
        my: null,
        myBinding: "App.router.myController" // <-- works
    });
    

    jsFiddle: demo

    0 讨论(0)
提交回复
热议问题