manip

2019-09-11 admin

manip是什么

什么是manip,A library for manipulating nested data in a way reminiscent of MongoDB's "Field Update Operators" work (eg. $set)

manip使用教程帮助文档

Manip

A library for manipulating nested data in a way reminiscent of MongoDB’s “Update Operators” work (eg. $set, $unset, $push and $inc)".

The following operations are current supported:

  • $set
  • $unset
  • $push
  • $inc

Given a set of data, sometimes you want to be able to be able to modify deeply nested data without hard coding the path to that data or worring if the sub sub subdocument you want to add to already exists.

Take the following example:

var jack = {
	eyes: 'blue',
	car: {
		ford: {
			wheels: 4,
			age: 3,
			color: 'blue'
		}
	}
};

I could increase the age of the car by one year

manip(jack, {'$inc': {'car.ford.age': 1}}));

and now the data is:

{
	eyes: 'blue',
	car: {
		ford: {
			wheels: 4,
			age: 4,
			color: 'blue'
		}
	}
}

Source Code

Source code is prepared using Browserify which is also compatible with Node.JS. There is a UMD bundle which can be used with AMD or a vanilla browser (where it will export a global called manip.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-74873.html

文章标题:manip

回到顶部