Ajouter une fonction pour renommer les clés dans un objet
> var _ = require('underscore');
> var note = {
... '_id': 1,
... 'title': 'Ruby is awesome..',
... 'text': '..and so is CoffeeScript'
... }
> console.log(_.rename(note, [['_id', 'id']]));
{ id: 1,
title: 'Ruby is awesome..',
text: '..and so is CoffeeScript' }
ou un tableau d'objets
> var notes = [note, note];
> console.log(_.rename(notes, [['_id', 'id']]));
[ { id: 1,
title: 'Ruby is awesome..',
text: '..and so is CoffeeScript' },
{ id: 1,
title: 'Ruby is awesome..',
text: '..and so is CoffeeScript' } ]
Merci,
Nisanth
Merci, mais non merci -- cas bien trop spécial pour le noyau Underscore. N'hésitez pas à le mélanger à vos propres fins.