gpt4 book ai didi

javascript - lodash:错误链接 mapValues

转载 作者:行者123 更新时间:2023-11-29 19:30:01 25 4
gpt4 key购买 nike

我正在努力链接 _.mapValues .这是代码

var result = _.mapValues(results[0], function(val, qname) {
return (results[1].hasOwnProperty(qname)) ? _.assign(val, results[1][qname]) : val
})
.mapValues(function(r) {r.total = addFields(r); return r;})

这导致运行时 TypeError: Object #<Object> has no method 'mapValues'对于第二个 mapValues。第一个 mapValues 工作正常。

最佳答案

在这种情况下,您需要使用方法 _.chain , 像这样

var result = _.chain(results[0])
.mapValues(function(val, qname) {
return (results[1].hasOwnProperty(qname)) ? _.assign(val, results[1][qname]) : val
})
.mapValues(function(r) {r.total = addFields(r); return r;})
.value();

关于javascript - lodash:错误链接 mapValues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28472552/

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