BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
855 stars 130 forks source link

"#content" or "~tag.tagCtx.content" ? #349

Closed ainglese closed 7 years ago

ainglese commented 7 years ago

Hi boris, i don't know if this is by design (and if so why) but if you look at this template (for a custom tag):

{^{for list}}
  {^{if #data[~tag.cultureField] == ~tag.localizableContext.currentCulture }}
  <span>A</span> {{include  tmpl=~tag.tagCtx.content /}}
  <span>B</span> {{include  tmpl=#content /}}
  {{/if}}
{{/for}}

when i add/remove an item to "list", using $.observable(list).insert(..), the new item is rendered, i can correctly see both "A" and "B", but the second include is not rendered on the newly added item. using the first include correctly works..

also note that items that are on the list when linking the template, correctly gets rendered (and updated) for both the include.

i've tried both {{include tmpl=#content /}} and {^{include tmpl=#content /}} but doesn't change

BorisMoore commented 7 years ago

Hi ainglese,

Yes you are right - that is a bug - thanks very much for calling it out.

I have a fix ready for the next update. You could test and let me know if works correctly for you.

Change this line: https://github.com/BorisMoore/jsviews/blob/master/jsviews.js#L1436 : to

|| new View(context, "array", view, data, tmpl, key, onRender, contentTmpl);

and this: https://github.com/BorisMoore/jsviews/blob/master/jsviews.js#L1451 to:

childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, newView.content);

Thanks, Boris

BorisMoore commented 7 years ago

Resolved in commit 82