【问题标题】:Vue.js - Set dynamic checkbox value true/falseVue.js - 设置动态复选框值真/假
【发布时间】:2020-07-30 11:14:52
【问题描述】:

我有一个包含一些产品列表的表格,现在每个产品都有一个上传文件和一个完整的复选框,

<vs-table :data="fileUpload">
   <template slot="header">
      <h3>
         Upload Files
      </h3>
   </template>
   <template slot="thead">
      <vs-th>
         Data
      </vs-th>
      <vs-th>
         Upload Files
      </vs-th>
      <vs-th>
         Uploaded
      </vs-th>
   </template>
   <template slot-scope="{ data }">
      <vs-tr :key="indextr" v-for="(tr, indextr) in data">
         <!--<vs-tr>-->
         <vs-td>
            {{tr}}
         </vs-td>
         <vs-td>
            <div class="centerx">
               <input type="file" v-on:change="handleFileUpload($event,indextr)" />
            </div>
         </vs-td>
         <vs-td>
            <vs-checkbox v-model="completedCheckboxes" :vs-value="indextr"></vs-checkbox>
         </vs-td>
      </vs-tr>
   </template>
</vs-table>

现在关于 handleFileUpload 的更改事件,我想将其旁边的复选框设置为 true。

handleFileUpload: async function(event,checkboxIndex) {
//set checkbox for that row here
}

 data() {
    return {
    completedCheckboxes:[],
 }
}

现在我确实得到了 completedCheckboxes 数组中的 checboxes 值p>

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component


    【解决方案1】:

    由于复选框是索引尝试将上传的文件索引推送到completedCheckboxes 数组:

    handleFileUpload: async function(event,checkboxIndex) {
        this.completedCheckboxes.push(checkboxIndex)
    }
    

    【讨论】:

    • 成功了,谢谢哥们继续努力!
    • @uneebmeer 需要async吗?
    • 在我的情况下,文件上传需要异步完成,这就是我添加的原因,这与您可以忽略的实际问题无关。
    猜你喜欢
    • 2016-09-01
    • 2013-12-09
    • 2014-05-10
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 2017-10-14
    • 2017-04-21
    • 2012-10-17
    相关资源
    最近更新 更多