javascript - v-for 用于在 ajax 中使用时使用循环和 select2 不起作用
问题描述
为什么我的脚本不起作用。我从 ajax 获取数据并使用 select2 来选择产品,当我尝试使用 v-for 为在 prev item 中选择的每个产品添加部分时使用循环。
这是我的html:
<div class="item form-group col-md-3 green box" style="display: none">
<label class="control-label" for="name">محصولات سفارشی<span class="required">*</span>
</label>
<select v-model="products_order" class="form-control reagent_selector" name="products_orders[]" multiple="multiple" id="">
@foreach ($products as $item)
<option value="{{$item->id}}">{{$item->name}}</option>
@endforeach
</select>
<textarea v-model="products_order_desc" v-if="products_order.length > 0" name="products_order_desc" cols="10"
rows="4" class="form-control" style="margin-top: 13px;" placeholder="توضیحات"></textarea>
</div>
<div class="col-md-3">
<div v-for="(order,indexx) in products_order">
<div class="item form-group">
<div>
<label class="control-label" for="name">منبع سفارش : @{{getProductById(order)}} <span
class="required">*</span>
</label>
<select v-model="selectedRes[order]" style="height: 43px;" class="form-control" name="" id="">
<option v-for="(item,index) in resources" :value="item.id">@{{item.name}} : @{{item.resource}}
</option>
</select>
</div>
</div>
</div>
</div>
这是 vue,js
products_order: function () {
let self = this;
let validator;
let irt;
if (self.products_order.length == 0) {
self.selectedRes = {}
}
Object.entries(self.selectedRes).forEach(function (item, ir) {
// console.log(item[0])
validator = false;
irt = null
self.products_order.forEach(function (itemm, indexx) {
if (itemm == item[0]) {
validator = true;
irt = itemm
}
})
if (validator == true) {
alert(irt)
delete self.selectedRes[irt];
}
});
}
解决方案
推荐阅读
- list - PyTorch DataLoader 返回列表而不是自定义数据集上的张量
- javascript - 在 html 正文中显示文本文件内容:如何在我可以在 HTML'body 上显示的变量中获取 XMLHttpRequest 的结果?
- ubuntu - 具有 FB 先知功能的多处理池,无法在 Gunicorn 上运行
- javascript - 如何使用 Material UI React 中的 Menu 和 MenuItem 在单击时获取 MenuItem 的名称
- firebase - 在 null 上调用了 getter 'postersImageUrl'。接收方:null 尝试调用:postersImageUrl
- terraform - Terraform AWS Elasticache 全局复制组辅助集群设置自动故障转移为 True
- python - Keras save_model() 和 load_model() 方法无法按预期工作
- c - 从文件读取后输出不打印到标准输出,在 C 中使用 printf ("%s", );
- javascript - 你如何在animejs中为translateZ设置动画?
- python - 我有 2 个列表,我想合并它们,答案应该如下所示