部分更新meteor中的会话变量?

部分更新meteor中的会话变量?,meteor,Meteor,我想我可能错过了什么。我已将用户产品订单的全部内容存储在会话变量中 var orderFormContents = { numDoors: 4 numWheels: 4 numSeats: 5 }; Session.set("orderFormContentsSessionVar", orderFormContents); 如何仅更新orderFormContentsSessionVar中一个键的值,例如,仅更新numDoors 我不想覆盖会话变量的全部现有内容 我希望能够做到以

我想我可能错过了什么。我已将用户产品订单的全部内容存储在会话变量中

var orderFormContents = {
  numDoors: 4
  numWheels: 4
  numSeats: 5
};

Session.set("orderFormContentsSessionVar", orderFormContents);
如何仅更新
orderFormContentsSessionVar
中一个键的值,例如,仅更新
numDoors

我不想覆盖会话变量的全部现有内容

我希望能够做到以下几点:

Session.set("orderFormContentsSessionVar.numDoors", 2);
相当于
\扩展

更新

根据下面的答案示例,我刚刚为其编写了一个函数:

var updateSession = function(sessionVarName, updateParams){
  var obj = Session.get(sessionVarName);
  _.extend(obj, updateParams);
  Session.set(sessionVarName, obj);
  console.log("updated session name: ", sessionVarName, "new session contents: ", Session.get(sessionVarName));
};

\uuu.extend
应该可以正常工作

Session.set(“orderFormContentsSessionVar”,
_.extend(Session.get(“orderFormContentsSessionVar”),{numsets:10}))


我怀疑还有别的办法。

像你建议的那样使用:

var obj = Session.get("orderFormContentSessionVar");
Session.set("orderFormContentsSessionVar", _.extend(obj, {numDoors: 2}));

是的,我想。谢谢我只是不确定Meteor的会话对象中是否内置了某种额外的属性,允许进行开箱即用的更新。