Spark View Engine If statement applied to attributes
Asked Answered
T

1

5

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>
Tlingit answered 4/12, 2009 at 15:51 Comment(0)
M
8
<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>
Morganite answered 4/12, 2009 at 15:51 Comment(3)
By the way I only found this feature recently in some PPT presentation; I couldn't find it on the Spark web site.Representational
Now it's there (sparkviewengine.com/documentation/expressions) under Conditional attribute output. Don't know about Dec 9.Germiston
@ArnisLapsa That site seems dead, is there any other source for conditional attributes?Totality

© 2022 - 2024 — McMap. All rights reserved.