aurelia / templating-binding

An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.
MIT License
32 stars 26 forks source link

$parent still required on show.bind #72

Closed bwdeleeuw closed 8 years ago

bwdeleeuw commented 8 years ago

The following code did not work as expected:

...
<li class="list-group-item" repeat.for="record of records | filter:'Name':recordFilterText" click.trigger="editToggle(record)">
  <span show.bind="editRecord !== record">${record.Name}</span><input type="text" show.bind="editRecord === record" value.bind="record.Name" />
</li>
...

The workaround I found was to add $parent to my editRecord, as follows:

...
<li class="list-group-item" repeat.for="record of records | filter:'Name':recordFilterText" click.trigger="editToggle(record)">
  <span show.bind="$parent.editRecord !== record">${record.Name}</span><input type="text" show.bind="$parent.editRecord === record" value.bind="record.Name" /> <i class="pull-right fa fa-trash-o fa-fw" click.trigger="deleteRecord(record)"></i>
</li>
...

as per the http://blog.durandal.io/2015/11/10/aurelia-pre-beta-release/ link, I expected to not have to use the $parent anymore?

jdanyow commented 8 years ago

@bwdeleeuw this sounds like you may not have the latest aurelia release installed. To force jspm to update you to the latest releases, locate this section in your package json and use it to craft a jspm install statement. Here's what the skeleton-navigation project's command to update would be based on this package.json:

jspm install aurelia-animator-css aurelia-bootstrapper aurelia-fetch-client aurelia-framework aurelia-history-browser aurelia-loader-default aurelia-logging-console aurelia-router aurelia-templating-binding aurelia-templating-resources aurelia-templating-router bootstrap fetch font-awesome text

you should also update systemjs:

jspm dl-loader --latest
bwdeleeuw commented 8 years ago

@jdanyow unfortunately not. I ran both of these commands, resolved a fork with text 0.0.2, and I still get this issue.

Just to make sure, here are my versions:

ok   Up to date - aurelia-fetch-client as npm:aurelia-fetch-client@^1.0.0-beta.1.0.1 (1.0.0-beta.1.0.1)
ok   Up to date - aurelia-framework as npm:aurelia-framework@^1.0.0-beta.1.0.3 (1.0.0-beta.1.0.3)
ok   Up to date - aurelia-router as npm:aurelia-router@^1.0.0-beta.1 (1.0.0-beta.1)
ok   Up to date - aurelia-templating-resources as npm:aurelia-templating-resources@^1.0.0-beta.1.0.2 (1.0.0-beta.1.0.2)
ok   Up to date - aurelia-history-browser as npm:aurelia-history-browser@^1.0.0-beta.1.0.1 (1.0.0-beta.1.0.1)
ok   Up to date - aurelia-bootstrapper as npm:aurelia-bootstrapper@^1.0.0-beta.1 (1.0.0-beta.1)
ok   Up to date - aurelia-animator-css as npm:aurelia-animator-css@^1.0.0-beta.1.0.1 (1.0.0-beta.1.0.1)
ok   Up to date - aurelia-loader-default as npm:aurelia-loader-default@^1.0.0-beta.1.0.1 (1.0.0-beta.1.0.1)
ok   Up to date - aurelia-templating-binding as npm:aurelia-templating-binding@^1.0.0-beta.1.0.1 (1.0.0-beta.1.0.1)
ok   Up to date - aurelia-templating-router as npm:aurelia-templating-router@^1.0.0-beta.1.0.2 (1.0.0-beta.1.0.2)
ok   Up to date - font-awesome as npm:font-awesome@^4.5.0 (4.5.0)
ok   Install tree has no forks.

ok   Install complete.
bwdeleeuw commented 8 years ago

In order to take any issues with my environment out of the equation, I created a plunker to show the issue. Hope that helps.

http://plnkr.co/edit/iBTZmT?p=preview

jdanyow commented 8 years ago

Here's a working plunker: http://plnkr.co/edit/pRJSrg?p=preview

Two tweaks to the original:

  1. app.html line 5: editItem needed to be editItem1 in two spots
  2. app.js lines 4 and 5: need to initialize the editItem1 / editItem2 properties with a value (anything, even undefined) otherwise aurelia's binding system will assume they're on the current scope when it can't find them on current scope or ancestor scopes. I think this is the primary issue you were running into.
bwdeleeuw commented 8 years ago

Thanks! That does make sense. Appreciate the response and the beautiful product!