从 属性 获取特定字段

Get specific field from property

我是 JavaScript 和 Dynamics CRM 的新手。 我有以下代码:

var analysisCode = Xrm.Page.getAttribute("rf_analysiscode").getValue()[0].entityValues;

作为 analysisCode 的值,我得到以下输出:

{
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
}

但我只想得到 rf_code。我如何找回它?

像这样将结果解析为 JSON:

const analysisCodeObj = JSON.parse(analysisCode);

这样得到rf_code

const rfCodeObj = analysisCodeObj["rf_code"];

试试这个:

analysisCode = {
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
};
let rf_code = analysisCode.rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);

如果您在字符串中获取输出,首先需要解析输出,然后您可以从中获取任何值 json。

试试这个:

analysisCode = '{"rf_name":{"name":"rf_name","value":"ABC"},"rf_code":{"name":"rf_code","value":"ABC"},"createdon":{"name":"createdon","value":"24.1.2022 10.39"}}'
let rf_code = JSON.parse(analysisCode).rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);