Closed paulvales closed 5 years ago
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.
"props" helped, thank you very much!
Good to know...
Hi! When index of array started not with 0 then template dont render. works: http://joxi.ru/krDqVQXsEQ1QPm dont work: http://joxi.ru/DrlzYW4tvYM9b2