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

Bind Agility Object to DOM element in page #114

Open
mahadevan-k opened this issue Jan 25, 2014 · 3 comments
Open

Bind Agility Object to DOM element in page #114

mahadevan-k opened this issue Jan 25, 2014 · 3 comments

Comments

@mahadevan-k
Copy link

Would be awesome if I could bind an agility object to an existing element on the page. e.g.

.....

var menu=$$({},$('.menu'),{}) ;

How can we achieve this?

@gaby64
Copy link

gaby64 commented Apr 18, 2014

change render in view object to

render: function(){
if(typeof this.view.format != 'string') {
this.view.$root = this.view.format;
this.view.format = this.view.format.html();
}
else if (this.view.$root.size() === 0) {
this.view.$root = $(this.view.format);
}
else {
this.view.$root.html( $(this.view.format).html() ); // can't overwrite $root as this would reset its presence in the DOM and all events already bound, and
}
return this;
}

and change

if (typeof args[1] === 'object') {
if(args[1].format)
$.extend(object.view, args[1]);
else
object.view.format = args[1];
}

@mahadevan-k
Copy link
Author

k, some basic stuff seem to work after a tweak to handle empty objects passed as the 'view' argument in the $$ constructors.

In render function:

if(typeof this.view.format != 'string' && !$.isEmptyObject(this.view.format)) {
this.view.$root = this.view.format;
this.view.format = this.view.format.html();
}
else if (this.view.$root.size() === 0) {
this.view.$root = $(this.view.format);
}

and

if (typeof args[1] === 'object') {
if(args[1].format || $.isEmptyObject(args[1]))
$.extend(object.view, args[1]);
else
object.view.format = args[1];
}

Will check more thoroughly as I implement code using the tweak.

@mahadevan-k
Copy link
Author

The view binding works great.

But if I did something like

<div class="agility article"><p data-bind="content">Lorem Ipsum</p>

And create the agility object using the above code, the model doesn't reflect the values, i.e.

article.model.get("content") is undefined

Is there a way to load the model from the DOM when the object is initialized?

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