NodeJS 对象内部的对象第一个feemap是静态的,在uuid内部的feemap将由动态地给出,并且它是一个对象,它将像值一样起作用

lh80um4z  于 2022-12-29  发布在  Node.js
关注(0)|答案(1)|浏览(94)
"feeMap": {
      "6874597a-3b20-40ea-bfa3-08358ad19793": {
        "id": "6874597a-3b20-40ea-bfa3-08358ad19793",
        "name": "visnhuuuu666",
        "description": "One Time fee",
        "cost": 13,
        "isOneTimeFee": true,
        "isProrated": false,
        "prorateToDay": false,
        "discountable": true,
        "prepayable": true
      }
    }
    inside feemap that id is a uuid how can do like that. this "6874597a-3b20-40ea-bfa3-08358ad19793": uuid is acts like object and that uuid only act as inner id value also how can I do like that dynamically is it possible. please help me this problem

我希望动态地给出对象内部的feemap,即uuid,它的行为类似于对象,也在该对象内部为id值,同样的对象uuid也将添加到此处

rt4zxlrg

rt4zxlrg1#

你可以在JS中使用字符串作为字段名,并像这样访问它们:

let feeMap = {};
feeMap["6874597a-3b20-40ea-bfa3-08358ad19793"] = {};
feeMap["6874597a-3b20-40ea-bfa3-08358ad19793"].id = "6874597a-3b20-40ea-bfa3-08358ad19793";
feeMap["6874597a-3b20-40ea-bfa3-08358ad19793"].name = "visnhuuuu666";
//and so on....

Please refer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#accessing_properties

相关问题