无法使用._find提取值

时间:2018-10-04 11:51:59

标签: json node.js lodash

我有以下node.js代码,我想在其中提取用户选择的值“ abc”作为名称。运行此代码时,结果为未定义:

let input= [
  {
    "param": [
      {
        "id": "name",
        "choice": [
          {
            "label": "abc",
            "value": "abc",
            "valueId": "abc"
          }
        ]
      },
      {
        "id": "alias",
        "choice": [
          {
            "label": "dsf",
            "value": "dsf",
            "valueId": "dsf"
          }
        ]
      },
      {
        "id": "description",
        "choice": [
          {
            "label": "",
            "value": "",
            "valueId": ""
          }
        ]
      },
      {
        "id": "Key",
        "choice": [
          {
            "label": "K",
            "value": "K",
            "valueId": "K"
          }
        ]
      },
      {
        "id": "tagKey",
        "choice": [
          {
            "label": "",
            "value": "",
            "valueId": ""
          }
        ]
      },
      {
        "id": "tagValue",
        "choice": [
          {
            "label": "",
            "value": "",
            "valueId": ""
          }
        ]
      },
      {
        "id": "multiquantity",
        "choice": [
          {
            "label": "1",
            "valueId": "1",
            "value": "1"
          }
        ]
      }
    ],
    "old": [],
    "current": null
  }
]

let result = (_.find(input.param, {id: "name"})).choice[0].valueId;
console.log("value"+result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>

似乎该逻辑不能提取正确的值。我需要输出为abc。请帮助

0 个答案:

没有答案