javascript - swig js filter "last" -


source json:

{  "rss": {     "$": {         "version": "2.0",         "xmlns:metadata": "http://rss.rbc.ru/metadata",         "xmlns:rbc_news": "http://purl.org/rss/1.0/modules/content/",         "xmlns:wfw": "http://wellformedweb.org/commentapi/"     },     "channel": {         "item": [             {...},             {...},             {...},             {...},             {...}         ]     } }  } 


swig js template, handles source json:

{%set root = rss.channel %}  { "items":[     {% item in root.item %}         {             "category":"{{item['metadata:category']}}",             "title":"{{ item.title }}"         }{% if item|last %},{% endif %}     {% endfor %} ] } 

i can't figure out how select last item. in output seems every item last item , first item in context of rss.channel.item. output is:

 { "items":[              {                "category":"autonews",                "title":"sometitle1"              },              {                "category":"sport",                "title":"sometitle2"              },              {                "category":"realty",                "title":"sometitle3"              },... 

it's required, comma appear after last item. can't solve problem in expression:

{% if item|last %},{% endif %} 

swig's documentation says:

// my_arr = ['a', 'b', 'c'] {{ my_arr|last }} // => c 

so wonder what's mistake?

the "|last" filter, make easier handle return value. if you're trying when last item comes in, should use "{% if loop.last %}things do{% endif %}"

see http://paularmstrong.github.io/swig/docs/tags/#for


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -