下面,您可以看到这两个日志的输出。第一行代码清楚地显示了我试图访问的属性的完整对象,但在下一行代码中,我无法使用配置访问它。Col_id_3(见截图中的“undefined”?)有人能解释一下吗?我也可以访问除field_id_4之外的所有其他属性。

console.log(config);
console.log(config.col_id_3);

这就是这些行在控制台中打印的内容


当前回答

在这个回答的背景下: https://stackoverflow.com/a/52994419

重新生成文件的解决方案可能并不总是可行的。去除字符串前的“非空格”字符。所以,如果你能修剪字段名,就能把事情清理干净。

就像这样:

const records = parse(csvData, {
      columns: (colNameArray) => {
        return colNameArray.map((value, index) => {          
          return index === 0 ? value.trim() : value;
        });
      },
      onRecord: mapper.mapRow
    });

如果您不关心这个的性能,也可以跳过索引检查。

其他回答

对我来说,这是一个与猫鼬有关的问题。

我正在循环从Mongo查询中得到的对象。我只需要删除:

items = await Model.find()

并将其替换为:

items = await Model.find().lean()

这可能会帮助某人,因为我有一个类似的问题,其中JSON.parse()返回一个对象,我可以在console.log()上打印,但我无法访问特定的字段,上述解决方案都不适合我。比如使用JSON.parse()和JSON.stringify()的组合。

var jsonObj = JSON.parse(JSON.stringify(responseText))

// where responseText is a JSON String returned by the server.

console.log(jsonObj) ///Was printing the object correctly
console.log(jsonObj.Body) /// Was printing Undefined  

我最终通过使用ExtJs Ext.decode()提供的不同解析器来解决这个问题;

var jsonObj = Ext.decode(responseText)
console.log(jsonObj.Body) //Worked...

检查是否在控制台中应用了任何筛选器。它发生在我在chrome控制台。

我今天也遇到了同样的问题。问题是由uglify-js引起的。在我执行了相同的非丑陋代码后,问题得到了解决。删除的

--mangle-props

从uglify-js中编写丑陋的代码就足够了。

也许,最好的做法是为那些必须被uglify-js的regex规则破坏的属性使用一些前缀。

来源如下:

var data = JSON.parse( content);
...
this.pageIndex = parseInt(data.index);
this.pageTotal = parseInt(data.total);
this.pageLimit = parseInt(data.limit); 

它是这样被丑化的:

var n = JSON.parse( t);
...
this._ = parseInt(n.index), this.g = parseInt(n.total), this.D = parseInt(n.C)

如果这是在使用Mongoose时发生的问题,则可能会发生以下情况:

console.log(object)

返回所有内容,包括所需的键。

console.log(object.key)

返回未定义。

如果发生了这种情况,就意味着Mongoose Schema中缺少键。添加它将解决这个问题。