javascript - 迭代对象
问题描述
我有一个这样的对象:
obj: {
'tags': {
'0': 'One',
'1': 'Two',
'2': 'Three',
'3': 'Four',
'4': 'Five',
'5': 'Six',
}
我这样做:
<div
v-for="(tag, index) in obj.tags">
<v-text-field
v-model="tag"
>
</v-text-field>
</div>
我想在 vuetify 文本字段中显示该值,但是当我执行 vfor 时,我收到以下消息:
<v-text-field v-model="tag">: You are binding v-model directly to a v-for iteration alias. This will not be able to modify the v-for source array because writing to the alias is like modifying a function local variable. Consider using an array of objects and use v-model on an object property instead.
我能怎么做 ?
解决方案
因为标签是您正在使用的对象的“别名”,所以我们不能通过该别名引用它。
但是,我们可以使用 v-for 中的索引将其重新绑定到原始对象。
这将为您绑定它。
<v-text-field v-model="obj.tags[index]">
</v-text-field>
推荐阅读
- django - 已删除 已解决,不再需要
- javascript - 如何从firebase获取数据并插入变量
- c# - 将 Packages.config 迁移到 PackageReference
- sql - postgres子查询中列的动态生成
- excel - 在范围内标记重复项,跳过空单元格
- kubernetes - 无法对 dahsboard kubernetes 进行身份验证:内部错误(500)(等待标头时超出 Client.Timeout)
- python - 如何在 Django 中使用 ListView 不显示任何记录?
- android - 如何在没有 Visual Studio 的情况下下载 Android SDK?
- azure-machine-learning-studio - 通过 REST 调用在 Azure ML Studio 中执行以下操作
- list - 从飞镖列表中删除重复项目时出现问题