【问题标题】:What's the preferred way to set values for select dropdowns?为选择下拉菜单设置值的首选方法是什么?
【发布时间】:2015-08-04 01:34:29
【问题描述】:

我有一个选择下拉菜单,我想知道在设置子选项的值时使用什么最佳约定。

这是我的表单域:

  <div class="field">
    <label for id="schedule_type">Schedule Type</label><br>
    <select name="schedule_type" id="schedule_type">
      <option value="recurring">Recurring — Create a series of sessions</option>
      <option value="nonrecurring">Not recurring — Create just one session</option>
    </select>
  </div>

请注意,我使用了值 "recurring" 和 "nonrecurring"。我也见过使用整数的例子:

<option value="1">Recurring — Create a series of sessions</option>
<option value="2">Not recurring — Create just one session</option>

我很迂腐?有没有比其他的优势?

【问题讨论】:

    标签: html ruby-on-rails forms drop-down-menu


    【解决方案1】:

    除了较大的[非平凡]页面大小(1 与 recurring 的值,字节差异很小,会影响页面呈现),没有什么问题前端。虽然这[可能]会影响后端。


    考虑一下(与后端无关):

    1. 我将recurring 上的form.submit 值传递给服务器 处理。
    2. 保存前,服务器会先查询实际调度类型的id是什么(即是否为外键)
    3. 然后保存。

    反对在保存时将实际的id 传递给服务器:

    1. 我将form.submit 上的值1 传递给服务器 处理。
    2. 然后保存。

    第二个会比第一个快。


    但同样,根据场景和后端的设计,一个可能优于另一个,或者根本可以忽略不计。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多