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

Cant bind functions to iteration items #15

Closed
lmartins opened this issue Apr 23, 2014 · 2 comments
Closed

Cant bind functions to iteration items #15

lmartins opened this issue Apr 23, 2014 · 2 comments

Comments

@lmartins
Copy link

I was trying to implement a simple list, based on the samples provided.

The following JS:

listTemplate = "<div class=\"ItemsList\">\n  <ul each=\"{{items}}\">\n    <li>\n      {{name}} <button on-click=\"{{ this.removeItem.bind(this, $index) }}\">Remove</button>\n    </li>\n  </ul>\n</div>";

List = ripple(listTemplate).use(each);

List.prototype.removeItem = function(index) {
  return this.data.items.splice(index, 1);
};

list = new List({
  data: {
    items: [
      {
        name: "Name1"
      }, {
        name: "Name2"
      }
    ]
  }
});

list.appendTo('.Page');

Renders to this:

<div class="ItemsList">
  <ul each="{{items}}"><li>
      Name1 <button on-click="function () {
    [native code]
}">Remove</button>
    </li><li>
      Name2 <button on-click="function () {
    [native code]
}">Remove</button>
    </li></ul>
</div>

And the button doesn't trigger the removeItem function which is part of the List prototype.

Any idea what I may be doing wrong?

@chrisbuttery
Copy link
Contributor

Hi @lmartins,
The missing plugin you're looking for is events. 👍

var List = ripple(listTemplate)
  .use(each)
  .use(events);

@lmartins
Copy link
Author

oohh, such a silly mistake.
Thanks @chrisbuttery

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