0
我希望像這樣的代碼:Lodash收集批量更新
_.bulkUpdate(myCollection,'meta.type','new');
換句話說,我希望我收集的字符串或功能更新領域,我知道這個功能是存在的,但不知道它的名字
我希望像這樣的代碼:Lodash收集批量更新
_.bulkUpdate(myCollection,'meta.type','new');
換句話說,我希望我收集的字符串或功能更新領域,我知道這個功能是存在的,但不知道它的名字
嘗試使用_.update
或_.updateWith
您可以通過使用_.forEach()
來遍歷數組,然後_.set()
值,或使用_.update()
一個有趣到位批量更新ction:
var arr = [{ id: 1 }, { id: 2 }, { id: 3 }];
_.forEach(arr, function(item, index) {
_.set(item, 'meta.type', 'new'); // to set a value
_.update(item, 'meta.value', function() { return index; }); // to set with a function
});
console.log(arr);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.3/lodash.min.js"></script>
是這個工程的一個元素,但不能散 – Ayman