- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将值从另一个对象附加到一个对象而不进行替换?
我正在尝试将 ObjectA 中的值附加到 ObjectB 作为子对象的名称。
正如您所知,ObjectA 有 4 个子对象,每个子对象都与一个 uid 关联。
因此,我尝试将每个子项的 uid 从 ObjectA 映射到 ObjectB。
这就是理想的代码
Object.keys(ObjectA).forEach(
(key) => _.assign(ObjectB, {'Product 07': true})
)
我尝试将每个 ObjectB 迭代注入(inject)源占位符 ES6 字符串插值,但它会失败,就像这样。
Object.keys(ObjectA).forEach(
(key) => _.assign(ObjectB, {`${basketObject[key].uid}`: true})
)
来源(JSON)
请使用此代码将对象的对象转换为带有_.mapValues的数组的对象,以从对象名称生成uid
var ObjectA = _.mapValues(data, (val, index) => {
return { ...val, index }
})
{
"Product": {
"Product 01": {
"approved": true,
"brand": "MANGO",
"category": "Woman",
"color": "Black,Bright Pink",
"description": "Rounded neck Chain detail Slit detail Zip fastening on the back section Inner lining · Side length 117.0 cm · Back length 135.5 cm These measures have been calculated for a S size.",
"imageURL": "https://s11.postimg.org/612lpusf7/73025590_80.jpg",
"name": "Chain Collar Dress",
"price": 499,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "S,M,L,XL"
},
"Product 02": {
"approved": true,
"brand": "MANGO",
"category": "Man",
"color": "Grey",
"description": "Modern coat that suits every man",
"imageURL": "https://s4.postimg.org/vub6umtlp/73079700_99.jpg",
"name": "Tailored wool-blend overcoat",
"price": 899,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "S,M,L,XL"
},
"Product 03": {
"approved": true,
"brand": "MANGO",
"category": "Kid",
"color": "Dark Navy, Offwhite, Light Pink,Medium Heather Grey",
"description": "Cotton fabric Spots print Rounded neck Short sleeve Embroidered Mango logo Decorated with sequins",
"imageURL": "https://s16.postimg.org/xkpg8qypx/73003605_56.jpg",
"name": "Logo cotton t-shirt",
"price": 29.9,
"purchasedUser": {
"mgzQBxjF9NNVACh18ID1xDPtrwH2": true
},
"size": "3-4 years,5-6 years, 7-8 years, 9-10 years, 11-12 years, 13-14 years"
},
"Product 04": {
"approved": true,
"brand": "UNIQLO",
"category": "Woman",
"color": "Red, Natural, Navy",
"description": "This comfortable women's shirt features the distinctive soft, warm, fuzzy feel of brushed 100% cotton flannel material. It looks great as a shirt or light outer layer, and the slightly loose cut gives it a relaxed style. The classic casual plaid design is available in a variety of colors.",
"imageURL": "https://s11.postimg.org/48sak0lmr/69_180861.jpg",
"name": "Flannel Check Long Sleeve Shirt",
"price": 79.9,
"size": "S,M,L,XL"
},
"Product 05": {
"approved": true,
"brand": "UNIQLO",
"category": "Kid",
"color": "Offwhite",
"description": "Star Wars™ A long time ago in a galaxy far, far awayLong after the Jedi Knights have perished, young Luke Skywalker has a fateful encounter with Princess Leia, a leader of the Rebel forces. Luke and Leia fight alongside Han Solo, Chewbacca, R2-D2 and C-3PO against the evil forces of Darth Vader to help restore peace in the galaxy. starwars.com © & ™ Lucasfilm Ltd. MATERIAL100% Cotton CAREMachine wash cold",
"imageURL": "https://s21.postimg.org/xdojmkx1z/01_185878.jpg",
"name": "BOYS STAR WARS Short Sleeve Graphic T-Shirt",
"price": 39.9,
"size": "110cm,120cm,130cm,140cm,150cm"
},
"Product 06": {
"approved": true,
"brand": "UNIQLO",
"category": "Man",
"color": "White,Dark Grey, Navy",
"description": "This amazing men's polo is made from next-generation, high-tech DRY-EX material. It dries sweat incredibly quickly to keep you feeling smooth, dry, and comfortable. The soft, cotton-like texture and cut allow for easy movement and combined, offer for superb comfort. In a fashionable striped pattern, perfect for warm-weather casual looks. MATERIAL[08Dark Gray] Body: 96% Polyester, 4% Nylon/ Rib: 100% Polyester [Other Colors] 100% Polyester CARE[08Dark Gray] Machine wash cold, gentle cycle [Other Colors] Machine wash cold",
"imageURL": "https://s11.postimg.org/bvm6i0ujn/00_169374.jpg",
"name": "MEN Dry EX Short Sleeve Polo Shirt",
"price": 99.9,
"size": "S,M,L,XL"
},
"Product 07": {
"brand": "FILANTO",
"category": "Woman",
"color": "Black",
"description": "Dress to impress this festive season with our must-have dresses. Our favourite piece for for creating effortlessly chic and glamorous look comes in the form of this delicate lace number. A form-fitting silhouette hugs and flatter your curves beautifully while its minimalist design makes it easy to dress it up or down.",
"imageURL": "https://s15.postimg.org/5qqq9496j/r1_top_fl20131894_002_a_btm_a_fl20131894.jpg",
"name": "Casual Long Dress",
"price": 59.9,
"size": "S,M,L,XL"
},
"Product 08": {
"brand": "HOTSHOTS",
"category": "Kid",
"color": "Off White",
"description": "Update her dress collection with this beautiful printed piece. Offering a short-sleeve design, round neckline and keyhole back button fastening. This dress also showcases a vibrant butterfly print motif. Sweet and demure, all this piece needs is a pair of flats to complete the look.",
"imageURL": "https://s16.postimg.org/ocebpd3h1/ho20129717_002_e_ho20129717.jpg",
"name": "Casual Short Dress Knit",
"price": 29.9,
"size": "4-5,6-7,8-9,10-11"
},
"Product 09": {
"approved": true,
"brand": "PADINI",
"category": "Man",
"color": "White",
"description": "Steeped in a solid white wash, this classic Oxford shirt gets a modern tweak with the addition of stripes across the body. It also features the iconic shirt collar, along with a chest pocket, buttoned cuffs and raised placket. This is the ultimate piece for curating both casual and formal looks.",
"imageURL": "https://s11.postimg.org/cvmbgxg2r/r1_top_pd20131998_003_b_btm_pd20131965_002_b_pd2.jpg",
"name": " Casual Long Sleeve Shirt",
"price": 89,
"size": "XS,S,M,L"
},
"Product 10": {
"brand": "PONEY",
"category": "Kid",
"color": "Navy",
"description": "This navy polo shirt designed with knight prints is Poney's new wardrobe classic. Made from 100% Cotton Fully Comb and Single Jersey. Features a neat polo collar, brown buttons, neckline lining in contrast fabric and leather patches.",
"imageURL": "https://s17.postimg.org/bcpbfwrcf/6j6a5351_2_1_1.jpg",
"name": "KNIGHT POLO SHIRT",
"price": 119,
"size": "7-8,9-10,11-12"
},
"Product 11": {
"brand": "PONEY",
"category": "Kid",
"color": "Navy",
"description": "This beautiful daisy print blouse with contrast sleeves is perfect for your best friend's birthday party. Pair with our \"Poney Daisy Print Jeans\" for a chic contemporary look or our \"Poney Tutu Skirt\" for a classic party look.",
"imageURL": "https://s12.postimg.org/la1o7vtm5/6j6a5327_1.jpg",
"name": "DAISY PRINT BLOUSE",
"price": 76,
"size": "1-2,2-3,3-4,4-5,5-6"
},
"Product 12": {
"brand": "GAMESTERS",
"category": "Kid",
"color": "Grey",
"description": "Ensure your little one is clothed in comfort and style with this super-cool and adorable jogger shorts from Gamester. Complete with an allover repetitive print, elasticated-drawstring waist, two front side pockets and one back pocket. Complement this shorts with any printed tee to complete his look.",
"imageURL": "https://s14.postimg.org/tz3xvg3z5/gm20130687_002_e_gm20130687.jpg",
"name": "Casual Knit Shorts",
"price": 29.9,
"size": "6-7"
}
}
}
最佳答案
应该可以
_.mapValues(ObjectA, (val) => {
ObjectB[val.uid] = true;
})
关于javascript - Lodash 从另一个对象追加对象而不进行替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40993587/
我想对一个字符串执行搜索和替换,比如 password。 正如您从问题中了解到的那样,替换后的字符串应变为 sdvvzrug。 但不幸的是,下面的代码输出bbbbcaab: $search = ran
我正在使用 futurize --stage2它应用了许多源代码转换以使代码 python2 和 python3 兼容。其中一个修复是所有分区 a/b 都替换为 old_div(a/b),我想避免这种
我正在使用 RStudio,但我在控制台上的输出被截断了。我找不到如何停止截断(我尝试搜索 ?options 以及在谷歌上搜索的时间比我想承认的要长)。 编辑:我向大家道歉!我最初的长名称为“This
我有一个 fragment 堆栈,我在其中使用替换和相加。添加或替换我的 fragment 的代码(在我的 Activity 中)如下 private fun addFragment(fragment
我在一个数组中插入了一些字符串,但在我这样做之前,我想按照主题所说的去做。只用 %20 替换空格,我这样做: Name.push(linkText.replace(" ", "%20")); 但是我如
我正在尝试编译和测试我在网上看到的代码 Expanding an IP add 。但是,当我尝试编译它时,我收到有关 StringBuilder 替换方法的错误。它说: IPadd.java:52:
我正在尝试使用 dplyr 的最新功能重写我的部分代码,方法是将 data.frame() 替换为 data_frame() 和 cbind() 与 bind_cols(): library(rgeo
我最近偶然发现了 replace()和 "[ x.tst s.tst s.tst [,1] [,2] [,3] [1,] 0 0 0
我一直想知道,如何在给定的参数内进行替换。 如果你有这样的一行: 123,Hello,World,(I am, here), unknown 你想更换 World与 Foobar那么这是一个简单的任务
如何转义字符串中的双引号?例如, input: "Nobody" output: \"Nobody\" 我尝试过这样的操作,但不起作用: String name = "Nobody"; name.r
我正在做类似的事情: SQL sql sQl SqL var ps = document.getElementsByTagName('p'); for(var i = 0; i 但它不会替换文本。
我正在尝试用 \" 替换所有 " 并用 JSON 解析字符串,但浏览器抛出错误 SyntaxError: JSON Parse error: Unrecognized token '\'. 下面是代码
大家好,在这里挣扎...... 是否可以将第一个正斜杠之间的任何内容替换为“”,但保留其余部分? 例如var 将是 string "/anything-here-this-needs-to-be-re
在下面的代码中,JavaScript 替换函数中的 alert(a) 将提醒匹配的字符串,在本例中,将是 {name} 和 {place}。 这按照文档 javascript docs 的描述工作,即
+-----------------------------+ | tables | +-------------------
我正在尝试用\"替换包含 "的字符串,下面是我尝试过的程序 String s="\"/test /string\""; s = s.replaceAll("\"", "\\\"");
var text = "a's ..a's ...\"... "; text = convert(text); function convert( text ) { var n = text
我正在尝试使用 JavaScript 中的替换函数,但有一个问题。 strNewDdlVolCannRegion = strNewDdlVolCannRegion.replace(/_existing
好吧,首先我对我的上一篇文章感到非常抱歉,但我真的需要帮助,我会把我真正想要的东西放在一个更清晰的代码中。我不擅长 javascript,所以希望你能帮助我。
我正在写一张纸条,遇到了障碍。可能有更有效的方法来执行此操作,但我对 Python 还很陌生。我正在尝试创建用户生成的 IP 地址列表。我正在使用 print 来查看生成的值是否正确。当我运行此代码时
我是一名优秀的程序员,十分优秀!