如何在 JavaScript 中将所有对象属性设置为 null? [英] How to set all object properties to null in JavaScript?

查看:33
本文介绍了如何在 JavaScript 中将所有对象属性设置为 null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Vue,突然一些使用

如您所见,文本和标签重叠.
使其工作的唯一方法是将属性设置为 null,即:

personal_info : {名称:空}

问题是我有数百个文本输入,我不想将所有内容都设置为 null.

是否有一种简单的方法可以将对象的所有属性设置为 null 而不是 1 乘 1 编码?

解决方案

checkout this snippet

var personal_info = {姓名:'约翰',电子邮件:'john@moto.com',电话:9876543210}console.log(JSON.stringify(personal_info));//循环前for (var key in personal_info ) {个人信息[key] = null;}console.log(JSON.stringify(personal_info));//循环后将值设置为'null'

I am using Vue and suddenly some of the computed css using vuetify is not working.

The way I declare an object is

personal_info : {}

and in my template, I could just do personal_info.name and other more in every v-model of text input.

I have no errors but suddenly the vuetify has a class called input-group--dirty that will elevate the label of the text input whenever it's not empty. But suddenly, it's not working. It looks like this:

As you can see, the text and label are overlapping.
The only thing that make it work is to set the property to null which is:

personal_info : {
  name: null
}

The problem is that I have hundreds of text inputs and I dont want to set everything to null.

Is there a simple way to set all of the object's properties to null instead of coding it 1 by 1?

解决方案

checkout this snippet

var personal_info = {
  name: 'john',
  email: 'john@moto.com',
  phone: 9876543210
}
console.log(JSON.stringify(personal_info)); //before looping

for (var key in personal_info ) {
  personal_info[key] = null;
}

console.log(JSON.stringify(personal_info));//after looping and setting value to 'null'

这篇关于如何在 JavaScript 中将所有对象属性设置为 null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆