Binding to a view property through the view's controller

I have a basic enyo 2.5.1.1 application. As I understand it, this is just an "enhanced" view controller. The app has 1 view. That view has a view controller which has several controls and manages several views. Like so:

enyo.kind({
    name: 'MyApplication',
    kind: 'enyo.Application',
    view: 'MainView',
    thing: 1
});

enyo.kind({
    name: 'MainView',
    test: 1,
    components: [
        {name: 'foo', kind: 'MyFoo'},
        {name: 'bar', kind: 'MyBar'},
        {name: 'foobar', kind: 'MyFooBar'},
        {name: 'content', kind: 'enyo.ViewController', resetView: true}
    ]
});

enyo.kind({
    name: 'SubView1',
    components: [
        {name: 'number', kind: 'enyo.Input'}
    ]
});

SubView2
SubView3
etc...

enyo.kind({
    name: 'MyFoo',
    prop: 1,
    components: [
        {name: 'stuff', content: 'stuff'}
    ]
});

MyBar
MyFooBar
etc...
What I'm trying to do is make a binding in MainView.foo like so:

bindings: [
     {from: 'app.view.test', to: '$.stuff.content'}
]
What I get is 'undefined' when I should get '1'.
In the end I would like to bind to app.view.$.content.view.$.number.value (the input in SubView1), but If I can't get the simple binding above to even work I don't see how I could do the more complex one.
If I log out enyo.getPath('app.view.test') I get the right value.
What am I doing wrong?

Comments

  • Can you try "^.app.view.test"? I wonder if the app hasn't been intialized completely and so the binding is not created?
  • One technique for debugging bindings is to add a transform function to the binding. You can log the arguments or set a break point.
  • edited January 2015
    @psarin‌ tried "^.app.view.test". That actually causes the binding to throw an error on Bindings.js:299 "Uncaught TypeError: undefined is not a function".

    @dmikeyanderson‌ Not quite understanding what is "at odds" about the binding. I always thought that referencing things like "parent" was considered poor form. Doesn't enyo.Application pass down a reference "app" precisely for this reason? The component would not be relocatable if I created the binding any other way? Also though I may be in the "MainView", I'm acutally in a sub-view of a view controller owned by the main-view. This would mean a binding like 'parent.parent.$.foo' wouldn't it?

    In the end I guess I'm confused. I thought the entire purpose and ability of bindings was to do exactly this. enyo.getPath takes a string. Things like model controllers proxy the values of the model and bindings can be created even if the model property of the controller is 'null'. I figured that a view controller acted as a proxy in a similar way.

    What is suggested to achieve a binding from a component of a view, through a different ViewController to a component of a view for that controller?
Sign In or Register to comment.