gpt4 book ai didi

javascript - Node 不打印完整对象

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:58 24 4
gpt4 key购买 nike

我被难住了..

我使用控制台中包含嵌套数组的另一个对象测试了此方法,并得到了预期的结果

db_status_emitter.on("components_found", function (returned_item) {
//console.log(returned_item);
prun_item.type = returned_item.type;
prun_item.components = returned_item.components.slice(0);
switch (prun_item.type) {

case "one-sided-mattress":

prun_item.quantity = prun_item.total_panel_quantity;
var top_panel = underscore.find(prun_item.components, function (element) {
return element.component_category == "top-panel"
});
var border = underscore.find(prun_item.components, function (element) {
return element.component_category == "border"
});
top_panel.quantity = border.quantity = prun_item.quantity;
top_panel.style = "91000000";
border.style = "81000000";
break;

case "two-sided-mattress":

prun_item.quantity = prun_item.total_panel_quantity / 2;
var top_panel = underscore.find(prun_item.components, function (element) {
return element.component_category == "top-panel"
});
var bottom_panel = underscore.find(prun_item.components, function (element) {
return element.component_category == "bottom-panel"
});
var border = underscore.find(prun_item.components, function (element) {
return element.component_category == "border"
});
top_panel.quantity = bottom_panel.quantity = border.quantity = prun_item.quantity;
top_panel.style = "91000000";
bottom_panel.style = "92000000";
border.style = "81000000";
break;

default:
console.error("error with prun Schedule");
break;
}
console.log(prun_item);
});

//编辑:我应该在此处添加 Mongoose 调用;它与 .on() 函数处于相同的范围内... I

fex_model.findOne({_id: prun_item.model}, {components: 1, type: 1, _id: 0}, function (err, returned_item){
if (err) db_status_emitter.emit("error", err)
db_status_emitter.emit("components_found", returned_item);
})

为什么没有一个组件显示我给它们的添加键值对?这是输出的示例..

{ quilter_name: 'Panel Quilter #3',
schedule_no: 55f32e4470df49a65d03cf6a,
model: '3630',
size: '66',
total_panel_quantity: 72,
type: 'two-sided-mattress',
components:
[ { component_category: 'top-panel', buffer_op: '120' },
{ component_category: 'bottom-panel', buffer_op: '120' },
{ component_category: 'border', buffer_op: '119' } ],
quantity: 36 }

但应该是:

{ quilter_name: 'Panel Quilter #3',
schedule_no: 55f32e4470df49a65d03cf6a,
model: '3630',
size: '66',
total_panel_quantity: 72,
type: 'two-sided-mattress',
components:
[ { component_category: 'top-panel', buffer_op: '120', quantity: 36, style: "91000000" },
{ component_category: 'bottom-panel', buffer_op: '120', quantity: 36, style: "92000000" },
{ component_category: 'border', buffer_op: '119', quantity: 36, style: "81000000" } ],
quantity: 36 }

但是为什么同样的过程在控制台上也能工作???

>underscore.extend(extended_this_object, components_wrapper);
{ foo: 'bar',
components:
[ { a: 'findthis', b: '3', c: '4', d: 'new value' },
{ a: 'notthis', b: '4', c: '5' } ] }
>var foundthis2 = underscore.find(extended_this_object.components, function(element){ return element.a == 'findthis'});

>foundthis2
{ a: 'findthis', b: '3', c: '4', d: 'new value' }
>foundthis2.e = 'a newer value'
'a newer value'
>extended_this_object;
{ foo: 'bar',
components:
[ { a: 'findthis',
b: '3',
c: '4',
d: 'new value',
e: 'a newer value' },
{ a: 'notthis', b: '4', c: '5' } ] }

编辑这是单个组件的键的输出。我怀疑它与来自 Mongoose 的它有关...

[ '__parentArray',
'__parent',
'__index',
'$__',
'isNew',
'errors',
'_doc',
'$__original_save',
'save',
'_pres',
'_posts',
'quantity',
'style' ]

请注意,数量和样式本身就是属性,并且我怀疑记录的属性位于 _doc 中的某个位置。

最佳答案

起初我认为这是一个有趣的问题,但后来我意识到这没有意义。我尝试在 js 文件中执行各种类似的操作并对其进行 Node 处理,但我无法复制您遇到的情况。

要么日志消息不是来自console.log,要么重启服务器后无法复制这个问题(V8 一下子出了问题?)。

您是否尝试过将日志参数更改为 prun_item.components[0].quantity 之类的内容?

或者也许您的原始代码比这复杂得多,并且修改从 _.find 返回的对象不会修改您 console.log 的对象,这这是唯一合乎逻辑的解释。

关于javascript - Node 不打印完整对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32530955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com