views:

174

answers:

1

Is there any better, cleaner, way to set selected="true" ? Maybe a nested if?

<select id="State" name="State" if="(Model.StateList.Count() > 0 )" >
    <option value="">Select One</option>
    <for each="KeyValuePair<string, string> item in Model.StateList">
        <option value="${item.Value}" if="(Model.State == item.Value)" selected="true" >${item.Key}</option>
        <option value="${item.Value}" if="(Model.State != item.Value)">${item.Key}</option>
      </for>
  </select>
+5  A: 
<select id="State" name="State" if="Model.StateList.Any()" >
        <option value="">Select One</option>
        <option each="var item in Model.StateList" value="${item.Value}" selected="true?{Model.State == item.Value}" >${item.Key}</option>
</select>
loudej
that's pretty cool.
Matt Hinze
By the way I only found this feature recently in some PPT presentation; I couldn't find it on the Spark web site.
queen3
Now it's there (http://sparkviewengine.com/documentation/expressions) under `Conditional attribute output`. Don't know about Dec 9.
Arnis L.