Spark View Engine If语句应用于属性

时间:2009-12-04 15:51:44

标签: spark-view-engine

有没有更好,更清洁,设置selected =“true”的方法?也许嵌套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>

1 个答案:

答案 0 :(得分: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>