BorisMoore / jsviews

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

{{for ..}} emits <tr> and <td> tags #441

Closed Autoflow closed 4 years ago

Autoflow commented 4 years ago

Hi, could someone please have a look at https://jsfiddle.net/2dtw8q05/. Why are the tr and td tags emitted? div-tags work fine ..

Within another fiddle https://jsfiddle.net/3gjmeuq5/2/ the data context is missing. Instead of the current array line it is linked to the global data object.

Best regards, Alexander

BorisMoore commented 4 years ago

I think you mean "why are the tr and td tags OMITTED"

See https://www.jsviews.com/#d.templates@fromscriptblock

Note: It is possible to declare a template in a non-script element such as a <div>, but this should be avoided. The browser will process the <div> content as HTML, with potential side-effects and perf implications. (For example if the template includes things like <img src="{{:...}}" />. then the browser will try to load the <img> from a non-existant URL…)

In your case, since inserting a tr or td directly under a div (which you do in your template declaration) produces invalid HTML, the browser is stripping out the invalid elements.

So if you follow the docs and use script blocks for declaratively declaring templates, all should work fine....