VUE / JavaScript变量的奇怪问题
老实说,我什至不知道如何搜索这个问题(要编写什么搜索参数),但无论哪种方式,它都很奇怪,我迫切希望寻求帮助。
因此,我正在尝试做一些简单的事情,事件发送“ form-change” ,当它做到时,我们将“ this.data”的新值设置为“ this.data” 对象。相当简单。我不希望 this.data 我只想更新它。
// Find our data object which we want to update/change
if (form.field.includes('.')) {
let find = form.field.split('.'), level = this.data;
for (let index = 0; index < find.length; index++) {
if (level[find[index]] !== undefined) {
level = level[find[index]];
} else {
level = undefined;
}
}
if (level !== undefined)
level = setFieldData();
}
这很简单,我们有字段“ ixply.book” 的名称(事件)时,我们只使用dots将dots分为多树并更新“ this.data.insprect。预订“ 新价值。但是它行不通。值不会改变。
实际上来自实际的值。
console.log(level);
,
this.data[ form.field.split( '.' )[ 0 ] ][ form.field.split( '.' )[ 1 ] ] = setFieldData();
但是 因此,“引用”变量不起作用...这是怎么可能的?看起来像JavaScript中的错误,还是具有VUE/反应性的东西?
有人有更好的主意如何使它工作吗?
I honestly don't even know how to search for this question (what search param to write) but either way its bit weird issue and I am desperate for help.
So I am trying to do something simple, event sends "form-change" and when it does, we set new value in "this.data" object. Fairly simple. I don't expect this.data to be reactive I just want to update it.
// Find our data object which we want to update/change
if (form.field.includes('.')) {
let find = form.field.split('.'), level = this.data;
for (let index = 0; index < find.length; index++) {
if (level[find[index]] !== undefined) {
level = level[find[index]];
} else {
level = undefined;
}
}
if (level !== undefined)
level = setFieldData();
}
This is fairly simple, we have name of field "inspect.book" and when update comes (Event) we just use dots to split into multi tree and update "this.data.inspect.book" to new value. But it does not work. Value does not change.
But the value from actual this.data.inspect.book comes out just fine using:
console.log(level);
However, if I do this:
this.data[ form.field.split( '.' )[ 0 ] ][ form.field.split( '.' )[ 1 ] ] = setFieldData();
It works fine. So "reference" to variable does not work... how is this possible? Looks like a bug in javascript or is it something with vue/reactivity?
Does anyone have better idea how to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您正在尝试使用符号更新表单数据?
我会做这样的事情:
如果以您的示例为例:
我替换
find.length
byfind.length -1
并替换
level = setFieldData()
bylats [find.pop()] = setFieldData()
您应该更新对象的属性,而无需实际覆盖值,
因为如果您覆盖值,则原始值将不会更新。
So you are trying to update form data using to notation ?
i would do something like that :
if i take your example :
i replaced
find.length
byfind.length - 1
and replaced
level = setFieldData()
bylevel[find.pop()] = setFieldData()
you should update the property of the object, without actually overriding the value,
because if you override the value, the original value will not get updated.