Underscore each to update collection
Underscore each to update collection
尝试使用下划线更新以下集合,但最后一次获胜(READ_ONLY变为false)将覆盖以前的所有更新。你知道怎么修吗?
_.each(availabilities, function(availability, availIndex) {
_.each(availability.POINTS, function(point, availPointIndex) {
if(availIndex == 0) {
point.READ_ONLY = true;
} else {
point.READ_ONLY = false;
}
});
});
这应该有效:
var availabilities = [
{
POINTS:[{READ_ONLY:true}, {READ_ONLY:true}, {READ_ONLY:true}]
},
{
POINTS:[{READ_ONLY:true}, {READ_ONLY:true}, {READ_ONLY:true}]
},
{
POINTS:[{READ_ONLY:true}, {READ_ONLY:true}, {READ_ONLY:true}]
}
]
_.map(availabilities, function(availability, availIndex) {
_.mapObject(availability.POINTS, function(point, availPointIndex) {
if(availIndex == 0) {
point.READ_ONLY = true;
} else {
point.READ_ONLY = false;
}
});
});
console.log(availabilities);
<script src="http://underscorejs.org/underscore-min.js"></script>
<pre>
[Object, Object, Object]
0: Object
POINTS: Array[3]
0: Object READ_ONLY: true
1: Object READ_ONLY: true
1: Object READ_ONLY: true
1: Object
POINTS: Array[3]
0: Object READ_ONLY: false
1: Object READ_ONLY: false
1: Object READ_ONLY: false
2: Object
POINTS: Array[3]
0: Object READ_ONLY: false
1: Object READ_ONLY: false
1: Object READ_ONLY: false
</pre>
相关文章:
- chrome.tabs.update() 重定向到 'chrome-extension://invalid/'
- 在node.js-mysql中执行UPDATE查询不起作用
- 我们可以用参数对象集合而不是原始数据来调用JavaScript collection.reduce()方法吗
- Underscore each to update collection
- Symfony2 - Collection + jQuery
- Backbone - Collection.add() / Collection.create() 之间的区别
- Backbone + RequireJS: Collection.each() is not working
- Visual Studio 2015 Update 2-'中的TypeScript模块;要求'未定义
- Java 8 Update 91 Issue
- MongoDB collection.find()查询挂起
- 如何从Backbone.Collection中删除模型
- 避免Meteor中Collection的持久性
- 如何在新的Meteor Collection文档中设置服务器上的created_on字段
- mongodb中db.collection.find()的返回类型是什么
- 不能从 Backbone.View 的方法调用 Backbone.collection 的方法,其中包含 require
- angularjs 中 ng-repeat 和 collection-repeat 之间的区别
- nodejs 和 MongoDB 的 collection.find() 没有响应
- .bind('all', 'update')上的主干怪异类型错误错误
- jQuery update cookie value
- Lodash Update Collection Where