【问题标题】:html select attribute does not display value from database instead display the first optionhtml select 属性不显示数据库中的值,而是显示第一个选项
【发布时间】:2021-04-01 06:19:01
【问题描述】:

我的代码遇到了这个问题,我在这里得到的选择属性不显示来自数据库的值,而是在选择字段中显示第一个选项。 代码如下:

<body>
   <g:form controller="customer" action="updateCustomer" class="updateCustomer" id="${cus.id}">
      <form>
         <div style="width:100%; padding-top: 50px; margin-right: auto; margin-left: auto; text-align: center">
            <div style = "height: 50vh; width: 70%; margin-left:auto; margin-right:auto;">
               <div>
                  %{--                        Table for customer client--}%
                  <table class="table table-striped" id="table t1">
                     <colgroup>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th colspan="5" style="height: 40px;>
                           <h6 style="font-weight: bold; margin-left: 40px;">
                              <g:link action="index" controller="customer">All Customers</g:link>
                              &nbsp;>>&nbsp;
                              <a href="#" onclick="goBack()">${cus.name}</a>&nbsp;>>&nbsp;EDIT
                           </h6>
                           </th>
                        </tr>
                        <tr>
                           <th colspan="5" style="height: 40px; text-align:center;background-color:lightseagreen">
                              <h6 style="font-weight: bold">EDIT CUSTOMER INFORMATION</h6>
                           </th>
                        </tr>
                

                        <tr style="height: 70px;background-color: #f7fafd;">
                           <td style = "width:30%;font-weight: bold; text-align: right;padding-right: 20px;"><span class="required">Status:</span></td>
                           <td style = "width:70%;font-weight: bold; text-align: left; padding-left: 20px;"> <g:select value = "${cus.status}" style = "width:90%" class="form-control" name="status" from="${["Active","Inactive"]}"></g:select></td>
                        </tr>


                        </tr>
                     </thead>
                  </table>
                  %{--                        End of table for customer client--}%
               </div>
            </div>
         </div>
      </form>
   </g:form>

在与 HTLM 中的 select 属性等效的

但是当我点击编辑按钮时,状态是“活动” 有什么想法可以解决这个问题吗? 非常感谢。

【问题讨论】:

    标签: javascript html css grails


    【解决方案1】:

    我必须用这个替换我的表格行:

       <tr style="height: 70px;background-color: #f7fafd;">
                                <td style = "width:30%;font-weight: bold; text-align: right;padding-right: 20px;"><span class="required">Status:</span></td>
                                <td style = "width:70%;font-weight: bold; text-align: left; padding-left: 20px;">
                                    <select style = "width:90%"class = "form-control" name="status">
                                        <option disabled selected value> -- Select an option -- </option>
                                        <option value="selectValue" disabled selected hidden>${cus.status}</option>
                                        <option value="Active" select>Active</option>
                                        <option value="Inactive" select>Inactive</option>
    
                                    </select>
                                </td>
                            </tr>
    

    【讨论】:

    • 我无法重现所描述的 g:select 标签的不当行为。如果您在github.com/grails/grails-gsp/issues 提出问题并附上一个演示问题的示例,我们将很乐意进行调查。感谢您的反馈。
    猜你喜欢
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多