如何将我的Ajax数据添加到bootstrap4卡

时间:2018-09-13 16:11:59

标签: javascript jquery bootstrap-4

这是我的html(ejs)文件的一部分,并且我有多种卡片形式(例如ID = myContent1,myContent2,myContetn3 ...),当切换i class = icon ...时,它们会接收ajax数据。激活功能(切换)时,接收到带有myContent编号的ajax数据映射(例如,接收到带有myContent1的ajax数据ID 1和myContent2的2 ...等)。

我想做的是,应该在执行我的html文件时加载ajax数据,并自动使用我的卡片表格进行映射(基于卡片ID号)

需要您的友好帮助。

   <div class="col-sm-6">
        <div class="card">
          <div class="card-header" id="cardHeader3" style="visibility: hidden;">unSaved</div>
          <div class="card-body">
            <i class="icon-plus icons font-2xl" id="icon3" style="font-size: 5rem !important;margin-left: 46%;cursor:pointer;" onclick="toggler('myContent_3');"></i>
            <div id="myContent_3" class="card-title" style="display: none;">
              <form action="" method="post">
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">sequence</span>
                    </div>
                    <input type="text" id="notiSeq_3" name="notiSeq" class="form-control" value="">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="fa fa-sort-numeric-asc"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">title</span>
                    </div>
                    <input type="text" id="title_3" name="title" class="form-control" value="">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="fa fa-tumblr"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">Link</span>
                    </div>
                    <input type="text" id="link_3" name="link" class="form-control" value="">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="fa fa-hand-o-left"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">exposureTime</span>
                    </div>
                    <input type="text" id="notiTime_3" name="notiTime" class="form-control" value="" readonly style="background-color:#FFFFFF">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="cui-calendar"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">Urgency</span>
                    </div>
                    <select class="form-control" id="viewYn_3" defaultValue="N">
                      <option value="N">N</option>
                      <option value="Y">Y</option>
                    </select>
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="icon-eye icons"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group form-actions">
                  <button type="button" class="btn btn-primary" onclick ="save('3')">Save</button>
                  <button type="button" class="btn btn-secondary" onclick="del('3')">Delete</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>

这是我的js文件的一部分。当前在切换卡片形式时可以使用。

function toggler(divId) {
   var tempId = divId.slice(-1);
   var x = document.getElementById("icon" + tempId);
   var y = document.getElementById("cardHeader" + tempId);

  $.ajax({
    url: GW_URL+'/myRestAPI/get/'+tempId,
    type:'get',
    contentType: "application/json",
    dataType : "json",
    cache: false,
    success : function(data){
        $("#notiSeq_" + tempId).val(data.exposureNo);
        $("#title_" + tempId).val(data.title);
        $("#link_" + tempId).val(data.link);
        $("#notiTime_" + tempId).val(data.exposureTime + " - " + data.exposureTime2);
        $("#viewYn_" + tempId).val(data.urgency);

    },
    error : function(jqXHR, textStatus, errorThrown){
        console.log(jqXHR.responseText);
    }
});

0 个答案:

没有答案