JSON镜头从创建镜头。从这个JSON开始:
var market = { foods : { fruits : [ 'apples' , 'oranges' ] , veggies : [ 'peas' , 'carrots' ] } };
我们可以使用JSON指针创建镜头。
var lens = require ( 'json-lens' );
var firstFruit = lens ( '/foods/fruits/0' );
var secondVeggie = lens ( '/foods/veggies/1' );
并使用它们从我们的JSON对象中获取值。
t.equal ( firstFruit ( market ), 'apples' );
t.equal ( secondVeggie ( market ), 'carrots' );
暂无评论