Re: New Additions to Template.js

Juerg Lehni <[email protected]>
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hi Maksim,

>>> Also I think it is useful to have functionality to iterate over
>>> objects (hashs) as well as Arrays, since often I want to didpaly a
>>> html table or list of values of an object and I don't worry about
>>> ordering/sorting it.
>>
>> That's good to know, I will add it again then. #length and
>> #isLast will not work on these loops though.
>
> As expected so no probs there.

I started to look into this, and realized it will not be as straight  
forward as I wished. The problem is that for hashes, we have key -  
value pairs, while for arrays we have numeric indices and values. Now  
for a hash, the loop variable probably should contain the value, and  
$variable#index should be the key, instead of the numeric index,  
right? Or should we add #key, and #index would still give a number?

I'm not sure yet how to implement this nicely, as I only know at  
runtime wether a loop object is an array or a hash object. And at  
that time, the loop is already hardcoded, so I cannot switch between  
for-in and normal for loops...

Jürg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.