Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  151] [ 6]  / answers: 1 / hits: 28788  / 12 Years ago, sat, april 28, 2012, 12:00:00

Is there any better ways to populate Jade based select fields, I am currently using this example. Is there any better ways to not ruin the template code?



the item value is 'day' example.



    select
repeation = [ 'no-repeat', 'day', 'week', 'month']
for item in repeation
if job.repeat == item
option(selected=true) #{item}
else
option #{item}


Also what about displaying multiple selections, when the item is array of ['day', 'week']?



// Edit small possible solution for multiple element



      enginges = [ 'google', 'bing', 'yahoo', 'duckduckgo']
for engine in enginges
option(selected=job.sources.indexOf(engine) != -1) #{engine}

More From » node.js

 Answers
78

You should be able to do something like:



for item in repeation
option(selected=job.repeat == item) #{item}


The same concept should be able to be applied to a multiple item select drop down.


[#85913] Thursday, April 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
debras

Total Points: 307
Total Questions: 98
Total Answers: 112

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
;