إضافة وظيفة لإعادة تسمية المفاتيح في كائن
> 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' }
أو مجموعة من الأشياء
> 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' } ]
شكرا،
نيسانث
شكرًا ، ولكن لا شكرًا - طريقة خاصة جدًا لـ Underscore الأساسية. لا تتردد في مزجها لأغراضك الخاصة.