Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with Alloy widgets #9

Closed
mpociot opened this issue Jan 26, 2015 · 4 comments
Closed

Usage with Alloy widgets #9

mpociot opened this issue Jan 26, 2015 · 4 comments

Comments

@mpociot
Copy link

mpociot commented Jan 26, 2015

Is there any possibility to pass an existing nano object to Alloy widgets (and make them work there as well...)?

I was thinking of something like this:

<Widget src="my.awesome.widget" id="myWidget" />

And in my controller, pass the nano object to the widget:

$.myWidget.nano = nano;

Is something like this possible with nano?

@dbankier
Copy link
Owner

Not sure you need to.You don't actually create a nano instance. The base nano function just binds the models and views. Not sure what you are looking to to do, but you might just want to pass the $model object to the widget and bind it there as well.

@mpociot
Copy link
Author

mpociot commented Jan 28, 2015

Okay. Here is a more detailed example to showcase my problem:

My widget XML view looks like this:

<Label id="title" />
<TextField id="field" />

What I've tried is:

In my controller:

<Widget src="my.awesome.widget" id="myWidget" binding="person.firstname" />

widget.js

var nano = require("nano");
nano.syntax(/\-\=(.+?)\=\-/gi);

$.field.value = '-=' + args.binding + '=-';

$.setBinding = function(model){
    nano( $, model );
}

And in my controller I do:

$.myWidget.setBinding( $model );

But the textfield value still remains empty (so it gets replaced by nano)

Hope this makes things clearer :)

@dbankier
Copy link
Owner

I just added an example of how I would do it.
The widget shouldn't know anything about binding on the public api (unless it uses it internally).
It should by simple UI that expose properties for its public api that the controller can bind against.
I pushed a new version as well to support that.

@dbankier
Copy link
Owner

just updated the widget example for two way binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants