BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.

Home Page:http://www.jsviews.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Index of first array element

paulvales opened this issue · comments

Hi! When index of array started not with 0 then template dont render.
works: http://joxi.ru/krDqVQXsEQ1QPm
dont work: http://joxi.ru/DrlzYW4tvYM9b2

Can you show the code you used to create an array with the index not starting with 0?
Better, can you create a code sample using JsRender which shows what you are doing? The screenshot of the array is not enough...

I create array on the backend Yii2 (replaced index array with id item of row in db), i think problem with missing length attribute in array

JsRender works in the client with javascript objects and arrays. A javascript array, such as [a, b, c] starts with index 0, and has a length attribute. Otherwise it is not an array.

Whatever you have on the backend, it must lead to specific javascript objects and arrays in the browser. This is not a valid JsRender issue unless you can provide a simple javascript repro of your problem...

yes, I got it, Thanks!

Just curious - Are you using JsRender templates on the server on yii2? If so, how? Did you use a yii2 extension or asset that integrates JsRender?

Backend on the Yii2, return JSON array, on frontend used JsRender for render this JSON array. When i reindex array, on backend, index keys replaced id items from db

http://joxi.ru/krDqVQXsEQ1QPm - this is returning an array [{id=1, ....}, {id=2, ....}, ...]
http://joxi.ru/DrlzYW4tvYM9b2 - this is returning an object (a hash) {1: {id=1, ....}, 2: {id=2, ....}, ...}

You can render using {{props items}} to iterate over the keys of an items object (hash)
You can render using {{for items}} to iterate over the keys of an items array.

See https://www.jsviews.com/#propstag@iterate-hash.

"props" helped, thank you very much!

Good to know...