Underscore: إضافة وظيفة لإعادة تسمية المفاتيح في الكائنات

تم إنشاؤها على ٩ يوليو ٢٠١٣  ·  1تعليق  ·  مصدر: jashkenas/underscore

إضافة وظيفة لإعادة تسمية المفاتيح في كائن

> 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' } ]

شكرا،
نيسانث

enhancement wontfix

>كل التعليقات

شكرًا ، ولكن لا شكرًا - طريقة خاصة جدًا لـ Underscore الأساسية. لا تتردد في مزجها لأغراضك الخاصة.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات

القضايا ذات الصلة

chikamichi picture chikamichi  ·  8تعليقات

jdalton picture jdalton  ·  4تعليقات

Francefire picture Francefire  ·  5تعليقات

xiaoliwang picture xiaoliwang  ·  3تعليقات

marcalj picture marcalj  ·  5تعليقات