- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 lodash 新手,但正如标题所述“我想将不存在的项目推送到已声明的对象中,如果它们尚不存在”,也就是说,如果我有
var lessdata = {
"id": 1004,
"name": "some event",
"bookmarked": false //not in moredata and I'd like to keep the var as is
};
var moredata = {
"id": 1004,
"name": "some event",
"time": { //from here
"hours": 2,
"minutes": 00,
"currency": "USD"
},
"place": "some place" //to here is new without '"bookmarked": false'
};
我希望将结果加载回 lessdata
变量中,并让结果看起来像这样
var lessdata = {
"id": 1004,
"name": "some event",
"time": {
"hours": 2,
"minutes": 00,
"currency": "USD"
},
"place": "some place",
"bookmarked": false
};
我一直知道如何在 Angular 中适本地使用 Lodash,但不确定是否需要使用 Angualar 的 forEach。
我尝试过两种方法。
version 1
lessdata= _.uniq(lessdata, function(moredata) {
return moredata;
});
version 2
angular.forEach(lessdata, function(lkey, lvalue) {
console.log("[-]lessdata---lkey: " + lkey + ", lvalue: " + lvalue)
angular.forEach(moredata, function(mkey, mvalue) {
console.log("[+]moredata---mkey: " + mkey + ", mvalue: " + mvalue)
lessdata=_.uniq(lessdata, function(moredata) {
return moredata;
});
})
})
$scope.event = lessdata
我假设使用_.uniq
是最好的方法?任何帮助将不胜感激,我创建了一个 codepen在这里。
TLDR:只需阅读标题
最佳答案
这就是lodash.defaults
是:
Assigns own and inherited enumerable properties of source objects to the destination object for all destination properties that resolve to
undefined
.
lodash.defaults(lessdata, moredata);
关于javascript - 我想将不存在的项目推送到已声明的对象中(如果它们尚不存在),则使用 Angular 中的 lodash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35236268/
我需要面对一个架构/设计决策。 我正在开发一个 Cordova/Meteor 应用程序,它具有独特的入门体验。新用户会看到一个向导,引导他们完成填写某些表单的步骤。 向导流程会等到最后一步才能注册用户
我想通过 psql 在空数据库中加载一些 SQL 函数: psql -d my_database -f fuctions.sql --set ON_ERROR_STOP=1 我使用 --set ON_
我是一名优秀的程序员,十分优秀!