StephenStephen StephenStephen - 4 months ago 14
Jade Question

Access more than one object property in Jade Iteration

I'm creating a simple iteration to loop through an array of objects in a Jade Template and add each to a select form's option elements. I need to pass the object when the form is submitted and display the name on the dropdown select field.

select(name= 'departure_stop', form = 'gtfsForm')
each stop in stops
option(value= stop) stop.stop_name


The above code renders in the following way. The object is successfully passed into the value field, but the stop.stop_name is passed into the DOM as a string.



Any ideas?

Answer

You need to add equal sign

option(value= stop)= stop.stop_name

BTW I think you don't want value to be [object Object] and want to use some property for value too.

option(value= stop.id)= stop.stop_name
Comments