【问题标题】:Handle Multi Data Like Array in Form在表单中处理像数组一样的多数据
【发布时间】:2020-01-22 21:22:50
【问题描述】:

如何发送像数组这样的表单数据

看下面的代码,我不能在product_attribute中设置索引['index must be here']['key']

<tr v-for="index in attributes">
    <td class="text-left">
    <input type="text" name="product_attribute['index must be here']['key']" value="" placeholder="attribute" class="form-control" autocomplete="off">
</td>
    <td class="text-left">
    <div class="input-group">
        <textarea name="product_attribute['index must be here']['value']" rows="5" cols="70" placeholder="text" class="form-control"></textarea>
    </div>
    </td>
</tr>

【问题讨论】:

标签: javascript html vue.js vuejs2 vue-component


【解决方案1】:

您可以使用v-bind:name 或简短的:name 绑定它,如下所示:

<input type="text" :name="product_attribute[index]['key']"  ...

  <textarea :name="product_attribute[index]['value']" 

【讨论】:

  • 我试过这个但在控制台 ReferenceError: product_attribute is not defined
  • 其实我不想用ajax来发送我想用表单请求发送的数据
  • 所以你应该这样做:name="'product_attribute['+index+']['value']"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
  • 2012-11-17
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多