在VUE JS中使用v-Model中的未知键进行循环
我有一个动态的刻面对象。 数据的一个示例可能是:
facets: {
type: ['type1', 'type2', 'type3'],
color: ['color1', 'color2']
}
我也有一个用于过滤器的空对象。 然后,我循环循环,并为每个方面进行复选框组。我希望v-Model
是过滤器。“ facet的名称”
,SO:filters.type
和filters.color
。我不知道正手的名字。我尝试在循环中使用钥匙,但这不起作用。
我的循环看起来像这样:
<li v-for="(facet, facetKey, facetIndex) in facets" class="filter-item">
<strong>{{ facetKey }}</strong>
<div v-for="(value, valueIndex) in facet" class="form__fieldset" :key="valueIndex">
<div class="form__field-wrap">
<input type="checkbox" v-model="filters[facetKey]" :id="value.toLowerCase().trim()" :value="value">
<label :for="value.toLowerCase().trim()">{{ value }}</label>
</div>
</div>
</li>
如果我硬码V模型到filters.type
,它将按预期工作。有人实现了这种动态V模型吗?
I have a dynamically made object of facets.
An example of the data could be:
facets: {
type: ['type1', 'type2', 'type3'],
color: ['color1', 'color2']
}
I also have an empty object for filters.
I then loop over the facets object and make checkbox groups for each facet. I want the v-model
to be filters."name of the facet"
, so: filters.type
and filters.color
. I do not know the names forehand. I tried using the key in a loop but that does not work.
My loop looks like this:
<li v-for="(facet, facetKey, facetIndex) in facets" class="filter-item">
<strong>{{ facetKey }}</strong>
<div v-for="(value, valueIndex) in facet" class="form__fieldset" :key="valueIndex">
<div class="form__field-wrap">
<input type="checkbox" v-model="filters[facetKey]" :id="value.toLowerCase().trim()" :value="value">
<label :for="value.toLowerCase().trim()">{{ value }}</label>
</div>
</div>
</li>
If I hardcode v-model to filters.type
, It works as intended. Has anyone achieved this type of dynamic v-models?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Populate
filters
with your facets propertiesHere is the playground link to a working example
Populate
filters
with your facets propertiesHere is the playground link to a working example