gpt4 book ai didi

java - Struts 2 jquery sj :select and json result

转载 作者:太空宇宙 更新时间:2023-11-04 06:34:41 25 4
gpt4 key购买 nike

我正在使用 struts 2 jquery 插件选择组件。

行动是:

SampleAction {

private List<SampleVO> samples; //With setters and getters
private List<AnotherVO> anotherList; //With setters and getters
private String anString; //With setters and getters

@Action(value = "/loadSelect", results = {
@Result(name = "success", type = "json")})
public String loadSomeSamples() {
samples = new ArrayList<SampleVO>();
//Put some object in samples.
return SUCCESS;
}
}

jsp是

<sj:select list="samples" />

问题是 json 插件将序列化操作中的所有属性(anotherListanString 等...),如下所示

{
"samples": {
"0": {"property":"a"},
"1": {"property":"b"},
"2": {"property":"c"}
},
"anString": "hello",
"anotherList": {
"0": {"prop1":"a","prop2":"b"},
"1": {"prop1":"c","prop2":"d"}
}
}

如果我将 json root 参数更改为 samples,则 js:select 将不起作用,因为它在返回的 json 中找不到任何名为 samples 的列表。返回的json为:

{
"0": {"property":"a"},
"1": {"property":"b"},
"2": {"property":"c"}
}

这个问题可以解决吗?有什么方法可以配置struts 2 json插件来生成

 {
"samples": {
"0": {"property":"a"},
"1": {"property":"b"},
"2": {"property":"c"}
}
}

或者为什么struts 2 jquery插件接受简单的json数组

最佳答案

您可以对 json 结果使用 includeProperties 参数。例如

@Result(type="json", params = {"includeProperties", "samples.*" })

再一个示例

@Result(type="json", params = {"root", "samples", "wrapPrefix", "{\"samples\":", "wrapSuffix", "}"})

关于java - Struts 2 jquery sj :select and json result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25580207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com