开发者

Howto append new value pair to existing json object in lawnchair

开发者 https://www.devze.com 2023-02-21 06:58 出处:网络
I was looking documentation at Lawnchair website and I am trying to figure out how do I insert new value pair to existing data.

I was looking documentation at Lawnchair website and I am trying to figure out how do I insert new value pair to existing data.

Following sample in Lawnchair website.

var peo开发者_JAVA百科ple = new Lawnchair('people'); 
var me = {name:'brian'};
people.save(me);

Now if I want to add "brian" age.

I kind of expected having something like people.append("{key:mykey, age:30}") but looks like there is no such a method?

Is there any any other way to do this?


I am not much familiar with LawnChair, but to the extent I can understand it, I would suggest something like the following:

people.find('r.name == "brian"', function(r){
    //remove 'r' (from the main storehouse) here somehow, I dont know how.
    r.key = yourkey
    r.age=30
    people.save(r)
});
  • Retrieve and save the entry
  • Remove the entry
  • add age field to the saved object
  • save it back! :-)

Do tell me if that helps. :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号