链接的 lodash v3 函数返回对象内容而不是键

Chained lodash v3 functions returning object contents rather than key

我有一个 var absurdPersonalities 其中 returns Object {aipAggressive: Object, aipAir: Object, aipBot: Object, aipCautious: Object, aipDefender: Object…} 这些对象每个都包含如下内容:

adv_eco_mod: 1.3
adv_eco_mod_alone: 0.85
basic_to_advanced_factory_ratio: 0
display_name: "!LOC:Absurd"
enable_commander_danger_responses: true
energy_demand_check: 0.8
energy_drain_check: 0.65
fabber_alone_on_planet_mod: 2
fabber_to_factory_ratio_advanced: 1
fabber_to_factory_ratio_basic: 1
factory_alone_on_planet_mod: 0.5
factory_build_delay_min: 0
go_for_the_kill: true
max_advanced_fabbers: 50
max_basic_fabbers: 20
metal_demand_check: 0.71
metal_drain_check: 0.54
micro_type: 2
min_advanced_fabbers: 3
min_basic_fabbers: 2
name: "Absurd"
neural_data_mod: 1
per_expansion_delay: 0
percent_air: 0.2
percent_bot: 0.25
percent_naval: 0.05
percent_orbital: 0.05
percent_vehicle: 0.45
personality_tags: Array[2]
priority_scout_metal_spots: true
starting_location_evaluation_radius: 400
unable_to_expand_delay: 0

目前我的代码如下:

_.sample(_.keys(_.omit(absurdPersonalities, "aipRandom")))

这个returns一个随机键作为来自对象的字符串,例如"aipAir"

但是当我链接代码时

_.chain(absurdPersonalities).sample().keys().omit("aipRandom").value()

它returns:

Object {0: "display_name", 1: "percent_vehicle", 2: "percent_bot", 3: "percent_air", 4: "percent_naval", 5: "percent_orbital", 6: "personality_tags", 7: "metal_drain_check", 8: "energy_drain_check", 9: "metal_demand_check", 10: "energy_demand_check", 11: "micro_type", 12: "go_for_the_kill", 13: "priority_scout_metal_spots", 14: "enable_commander_danger_responses", 15: "neural_data_mod", 16: "unable_to_expand_delay", 17: "per_expansion_delay", 18: "factory_build_delay_min", 19: "adv_eco_mod", 20: "adv_eco_mod_alone", 21: "fabber_to_factory_ratio_basic", 22: "fabber_to_factory_ratio_advanced", 23: "fabber_alone_on_planet_mod", 24: "basic_to_advanced_factory_ratio", 25: "factory_alone_on_planet_mod", 26: "min_basic_fabbers", 27: "max_basic_fabbers", 28: "min_advanced_fabbers", 29: "max_advanced_fabbers", 30: "starting_location_evaluation_radius", 31: "name", 32: "percent_land"}

我不清楚我在链接时哪里出错了,或者这是否只是无法链接的东西。

您的第一个(工作)表达式首先执行 omit,然后执行 keys,最后执行 sample。请注意该表达式是如何从内到外解析的。

链接时,必须保持相同的顺序:

_.chain(absurdPersonalities).omit("aipRandom").keys().sample().value()