vue實(shí)現(xiàn)左右多選框

先上效果圖:


image.png

html部分代碼

<div class="form-inline">
<label>接口名稱:</label>
  <div class="input-group">
    <input type="text" class="form-control" id="apiKeyword">
    <span class="input-group-btn">
      <button type="button" class="btn btn-info btn-flat" v-on:click="searchApi">搜索</button>
    </span>
  </div>
</div>
<br/>

<fieldset>
  <table class="table table-bordered dchannel-table">
    <tbody>
    <tr>
      <td><span style="width: 50%;">搜索結(jié)果:接口名字(接口包名)</span></td>
      <td style="width: 50px;" valign="middle"></td>
      <td><span style="width: 50%;">待添加接口</span></td>
    </tr>
    <tr class="item-default">
      <td align="right" style="width: 50%;">
        <select id="sel_all_area" multiple="multiple" size="10" style="width:100%;height: 400px">
          <option v-for="api in resultApiList" :value="api.id">{{api.name}}({{api.packageName}})</option>
        </select>
      </td>
      <td style="width: 50px;" valign="middle">
        <button type="button" class="btn btn-default btn-small" id="btn_select_all_area" v-on:click="selectAllApi"><span class="glyphicon glyphicon-forward"></span></button>
        <button type="button" class="btn btn-default btn-small" id="btn_choose_selected_area" v-on:click="selectOneApi"><span class="glyphicon glyphicon-chevron-right"></span></button>
        <button type="button" class="btn btn-default btn-small" id="btn_remove_selected_area" v-on:click="removeOneApi"><span class="glyphicon glyphicon-chevron-left"></span></button>
        <button type="button" class="btn btn-default btn-small" id="btn_remove_all_area" v-on:click="removeAllApi"><span class="glyphicon glyphicon-backward"></span></button>
      </td>
      <td style="width: 50%;">
        <select id="sel_selected_areas"  multiple="multiple" size="10" style="width:100%;;height: 400px">
          <option v-for="api in toAddApiList" :value="api.id">{{api.name}}({{api.packageName}})</option>
        </select>
      </td>
    </tr>
    </tbody>
  </table>
</fieldset>

js動(dòng)作

selectAllApi(){
  this.toAddApiList = this.resultApiList;
  this.resultApiList = [];
},
selectOneApi(){
  for(let i=0;i<this.resultApiList.length;i++){
    if(this.resultApiList[i].id == $("#sel_all_area").val()){
      this.toAddApiList.push(this.resultApiList[i])
      this.resultApiList.splice(i,1);
    }
  }
},
removeOneApi(){
  for(let i=0;i<this.toAddApiList.length;i++){
    if(this.toAddApiList[i].id == $("#sel_selected_areas").val()){
      this.resultApiList.push(this.toAddApiList[i])
      this.toAddApiList.splice(i,1);
    }
  }
},
removeAllApi(){
  this.resultApiList = this.toAddApiList;
  this.toAddApiList = [];
}

最后補(bǔ)充數(shù)據(jù)部分作為參考:

data() {
    return {
      resultApiList:[
        {"id":2,"name":"600014","packageName":"user.LoginService","type":"1","groupName":"USER","creater":"admin","createTime":"2019-07-22 16:34:06","updater":"admin","updateTime":"2019-07-22 16:54:11","remark":"渠道用戶登錄接口"},
        {"id":3,"name":"600015","packageName":"user.LoginService","type":"1","groupName":"USER","creater":"admin","createTime":"2019-07-22 16:34:06","updater":"admin","updateTime":"2019-07-22 16:54:11","remark":"渠道用戶登錄接口"},
        {"id":4,"name":"600016","packageName":"user.LoginService","type":"1","groupName":"USER","creater":"admin","createTime":"2019-07-22 16:34:06","updater":"admin","updateTime":"2019-07-22 16:54:11","remark":"渠道用戶登錄接口"}
      ],
      toAddApiList:[],
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容