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

model.at(DOM node) gives the wrong object #158

Closed
ile opened this issue Oct 24, 2012 · 6 comments
Closed

model.at(DOM node) gives the wrong object #158

ile opened this issue Oct 24, 2012 · 6 comments

Comments

@ile
Copy link

ile commented Oct 24, 2012

https://groups.google.com/forum/?fromgroups=#!topic/derbyjs/-RaUK0cH0Ak

I'm having a problem getting the model from a DOM object. I have a list (ul) of things, made with #each. Model.at() gives a wrong object.

Template:

<Body:>
    <ul>
        {#each _items}
            <li x-bind="click:text">{.price}</li>
        {/}
    </ul>

_items:

model.set '_items', [
  { name: 'Can', price: 5.99, url: '/p/0' }
  { name: 'Fin', price: 10.99, url: '/p/1' }
  { name: 'Bot', price: 24.95, url: '/p/2' }
]

Bound function:

  exports.test = (e, el) ->
    console.log(model.at(e.target).get())

So, the HTML page looks like this:

  • 5.99
  • 10.99
  • 24.95

When I click the first one on the list, I get this output:

Object {name: "Fin", price: 10.99, url: "/p/1"} 

This is the next (2nd) one in the model, not the first one I clicked. If I click the 2nd from the list, it would skip to the fourth one if there was anything there.

Also the same happens if I use the el variable instead of e.target in the test function.

So.. I'm at loss here. Is this a bug, anyone seen this? I'm using derby 0.3.13.

@ile
Copy link
Author

ile commented Oct 29, 2012

Here's a testcase for it.

The issue can be seen in the url /pim which renders the pim.html file.

Url / (index.html) has the same content as /pim, but model.at(DOM node) works there.

modeltest.tar.gz

@reneclaus
Copy link

I had the same problem. I just submitted a patch. The problem is the whitespace between the li tag and the {#each}. If you remove it the problem should go away. [https://github.com//pull/162]

@ile
Copy link
Author

ile commented Nov 14, 2012

My issue was different. The testcase above shows the problem.

@ile
Copy link
Author

ile commented Jan 31, 2013

BTW, I needed at least two things: 1) getting rid of the white space and 2) adding the end tag to the component.

@IvanGaravito
Copy link

Hi @ile, try the changes I proposed at #204 for model.at function into derby.Model.js file. That got my app to work again even with nested each loops and lot of conditional blocks, and no matter if there are spaces or comments.

@nateps
Copy link
Contributor

nateps commented Apr 10, 2014

Master of Derby is now the rewritten 0.6 and I am removing previous issues pretty aggressively so that I can be more responsive to new issues.

Please re-open if this issue is still relevant in Derby 0.6.

@nateps nateps closed this as completed Apr 10, 2014
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

Successfully merging a pull request may close this issue.

4 participants