我有方法:
export const groupActivities = ({ activities, tags, images, tickets }) => { if (!activities || !tags) { console.error('Must have activities and tags'); } const groupActivities = Object.assign({}, activities); const groups = groupByTags({ activities: groupActivities, tags }); groups.forEach(group => { group.length = group.activities.length; console.log(group.length); group.activities.forEach(activity => { if (images) { activity.images = activity.imageIds.map(id => images[id]); } if (tickets) { console.warn('No tickets provided to the groupactivities helper. May cause problems.'); activity.tickets = activity.ticketIds.map(id => tickets[id]); } }); }); return groups; };
Object.assign正在复制活动对象,但仍保留对其的引用,因此,如果我找到特定的活动并更改了它的某些属性,它也会更改原始对象!(更改groupActivities ['someID']。name ='name'会更改活动对象上的相应活动!)
这导致了一些奇怪的错误。有什么办法吗?
使用babel 5进行编译。