apex - 空 JSON 值 (LWC)
问题描述
大家
好,我正在尝试从 apex 方法中获取一些“硬编码”值,但是当我编写 console.log 时,它是空的。
这是我正在处理的代码:
@wire(getValues)
wiredValues({error, data})
if(data) {
console.log("Data::::::",data);
this.getVal = JSON.stringify(data);
} else if(error){
this.error = error;
this.getVal = undefined;
console.log("No values");
}
这是我的顶点方法(我正在尝试制作一种“假”标注,但我不确定我是否正确):
public without sharing class getSomeValues {
@AuraEnabled(cacheable = true)
public static List<wrapVal> getWrapVal() {
HttpResponse request = new HttpResponse();
request.setBody('{"Values": ["1000", "2000", "3000", "4000", "5000"]}');
Map<String, Object> results = (Map<String, Object>)
JSON.deserializeUntyped(request.getBody());
List<Object> sumVal = (List<Object>) results.get('Values');
List<wrapVal> newLstValues = new List<wrapVal>();
for (Object getValues : sumVal ) {
wrapVal newLstValue = new wrapVal();
newLstValue.nwValue = String.valueOf(getValues);
newLstValues.add(newLstValue);
System.debug("getValues::::::"+ newLstValue.nwValue);
}
return newLstValues;
}
public class wrapVal {
public String nwValue { get; set; }
}
所以我知道我做错了什么,如果可以与我分享一些建议或文档,那就太好了。谢谢
解决方案
似乎您需要使用@AuraEnabled 装饰类 wrapVal 的属性。否则 LWC 将不会收到它们。
public class wrapVal {
@AuraEnabled
public String nwValue { get; set; }
}
推荐阅读
- php - 为什么 bccomp 需要秤才能正常工作?
- simple-html-dom - 简单的 html dom 查找返回 NULL
- r - KNN 的 Ind 函数
- kotlin - 有没有办法改变 IntelliJ Kotlin 编码风格以在函数之后或文件末尾捕获额外的空白?
- netbeans - 我如何知道软件是 64 位还是 32 位(x64 或 x32)
- c - 打印字符串的所有字符(包括转义序列)
- json - 子类化 JSON (Swift) 时出错
- vue.js - v-slot 的含义:activator="{ on }"
- python - 将 Pandas 2 个数据框合并为一张图
- c# - Bot Framework 简单切换场景