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

Access the parent model/view from each's subView #140

Closed
cristiandouce opened this issue May 30, 2014 · 2 comments
Closed

Access the parent model/view from each's subView #140

cristiandouce opened this issue May 30, 2014 · 2 comments

Comments

@cristiandouce
Copy link
Member

Is there a way to access a parent "main" model/view from an each sub-view?

I've tried with this.model, reactive.model, model.prop, with no luck.

Every time the getter function compiles to reactive.get('reactive.model.blah') instead of what I really want.

Here a screenshot:

@defunctzombie
Copy link
Contributor

Your screenshot doesn't make sense to me without additional code.

What do you want to access? The main model or the main view?

Do you mean access in the template or in the js? There is no way currently to access any parent properties in the template within an each sub view (I don't think).

@cristiandouce
Copy link
Member Author

Yeah, the last. I'd like to access the parent properties/methods within an each sub view.

Let's say I have a menu with a current prop and an array of items:

var menu = {
  current: '',
  items: [{name: 'home', title: 'Homepage' }, ....]
}

Then this view:

<ul>
  <li each="items" class="{name === **menu**.current ? 'active' : ''}" on-click="onselect" data-text="title"></li>
</ul>

And a view with the following handler on click:

function View () {
  this.menu = menu;
  this.view = reactive(template, this.menu, { handler: this });
}

View.prototype.onselect = function () {
  // get the value `name`
  this.reactive.set('current', name);
}

And I would expect that way that the "active" class toggle wheter the current item is the clicked/selected one or not. (Avoiding to manually touch the DOM unselecting and selecting by removing adding that class... reactive already manipulates the DOM, so why should I do it too?)

Does that make any sense?

I know it's currently not supported, but is a feature that would make developing reactive views easier IMHO.

Don't get me wrong. I don't mind doing some dom('.active', this.view.el).removeClass('active') and then dom(el.target).addClass('active'). But this could get done with reactive.

Sorry for the lame issue's description before.

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