将记录数据绑定到sails.js中的输入表单值

时间:2018-11-15 06:35:22

标签: sails.js

我对Sails.js很陌生。我正在尝试从控制器中的数据库中获取记录。然后在我的ejs文件中,我有以下代码为数据库中的每条记录创建一个ajax形式(使它们能够更新记录。我不确定自己做错了什么。

fn: async function (inputs, exits) {
            var maplayers = await Maplayers.find().populate('layerstyle');
            return exits.success({
                maplayers: maplayers
            }); 

    }

然后在我的ejs文件中:

<% _.each(maplayers, function (maplayer) { %>
            <ajax-form action="updateMaplayers" :syncing.sync="syncing" :cloud-error.sync="cloudError" @submitted="updateMapLayerSubmit()" :handle-parsing="handleUpdateMaplayerParsingForm">
                <div class="accordion" id="maplayers-accordion">
                  <div class="card">
                    <div class="card-header" id="maplayer-header" data-toggle="collapse" data-target="#collapseOne-<%= maplayer.layerid %>">
                      <h5 class="mb-0">
                        <button class="btn btn-link maplayer-header-btn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                          <%= maplayer.name %>
                        </button>
                      </h5>
                    </div>

                    <div id="collapseOne-<%= maplayer.layerid %>" class="collapse" aria-labelledby="headingOne" data-parent="#maplayers-accordion">
                      <div class="card-body">
                        <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label for="maplayer-editlayerid">Layer ID</label>
                                <input class="form-control" id="maplayer-editlayerid" name="maplayer-editlayerid" type="text" value="<%= maplayer.layerid %>" :class="[formErrors.editlayerid ? 'is-invalid' : '']" v-model.trim="formData.editlayerid"  focus-first>
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label for="maplayer-editlayertype">Layer Type</label>
                                <select class="form-control" id="maplayer-editlayertype">
                                  <option value="point" <%= maplayer.layertype == 'point' ? 'selected' : ''%> >Point</option>
                                  <option value="polygon" <%= maplayer.layertype == 'polygon' ? 'selected' : ''%> >Polygon</option>
                                  <option value="line" <%= maplayer.layertype == 'line' ? 'selected' : ''%> >Line</option>
                                </select>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label for="maplayer-editname">Layer Name</label>
                                <input class="form-control" id="maplayer-editname" name="maplayer-editname" type="text" value="<%= maplayer.name %>">
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-4">
                              <div class="form-group">
                                <label for="maplayer-edittable">Table</label>
                                <input class="form-control" id="maplayer-edittable" name="maplayer-edittable" type="text" value="<%= maplayer.layertableref %>">
                              </div>
                            </div>
                            <div class="col-sm-4">
                                <label for="maplayer-editmin">Minimum Zoom</label>
                                <input class="form-control" id="maplayer-editmin" name="maplayer-editmin" type="number" value="<%= maplayer.minzoom %>">
                            </div>
                            <div class="col-sm-4">
                                <label for="maplayer-editmax">Maximum Zoom</label>
                                <input class="form-control" id="maplayer-editmax" name="maplayer-editmax" type="number" value="<%= maplayer.maxzoom %>">
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-12">
                                <div class="form-group">
                                    <label for="maplayer-editatt">Attributes to Display:</label>
                                    <textarea class="form-control" rows="3" id="maplayer-editatt" name="maplayer-editatt" ><%= maplayer.layerattributesonclick %></textarea>
                                </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-12">
                                <div class="form-group">
                                    <label for="maplayer-editurl">URL:</label>
                                    <textarea class="form-control" rows="3" id="maplayer-editurl" name="maplayer-editurl" ><%= maplayer.url %></textarea>
                                </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <p class="text-danger" v-if="cloudError === 'emailAlreadyInUse'">There is already an account using that email address.</p>
                              <p class="text-danger" v-else-if="cloudError">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</p>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group text-right">
                                <button type="button" class="btn btn-warning fontColor" @click="hideAddForm()">Cancel</button>
                                <ajax-button type="submit" :syncing="syncing" class="btn btn-success">Save changes</ajax-button>
                              </div>
                            </div>
                          </div>
                      </div>
                    </div>
                  </div>
                </div>
            </ajax-form>
        <% }) %>

我不知道为什么maplayers-editlayerid中的输入为空白?这是“层ID”字段。为什么未设置value = <%maplayer.editlayerid%>?

Lists out all the maplayers and adds the ability to update records

0 个答案:

没有答案