本文介绍了如何在SlingModel使用悦目列表中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能够在光线充足的显示值是一个POJO / SlingModel的一部分。请大家帮帮忙。
所需的输出
商品1
产品1,产品2,产品3
商品2
产品2,产品4,产品5
悦目code
<! - LIST ::索具模型 - 决赛 - >
< DIV数据sly-
use.model =$ {'com.tti.tticommons.service.models.LeadTimeTrendsModel@
rawJson = ws.JSON}数据SLY-展开>
< DIV数据SLY-list.commodity =$ {model.getProductsList}>
< DIV CLASS =面板面板默认>
< DIV CLASS =面板标题>
< H3类=面板标题>吊带模型(名单) - $ {commodity.name @
上下文='HTML'}< / H3>
< / DIV>
< DIV CLASS =面板体数据sly-
list.pr =$ {model.getProductsList.getProducts}>
< DIV CLASS =COL-MD-4 COL-SM-12行业列表组NO-
边境>
< DIV>
&其中;一类=>
$ {model.getProductsList.getProducts [PR]}
&所述; / a取代;
< / DIV>
< / DIV>
< / DIV>
< / DIV>
< / DIV>
< / DIV>
我的吊带模型类
公共类LeadTimeTrends {
私人列表<商品> productsList;
公开名单<商品> getProductsList(){
...商业逻辑?
...........
返回productsList;
}
公共类商品{
公共字符串code;
公共字符串名称;
公众的LinkedHashMap<字符串,产品与GT;产品;
公共无效商品(字符串code,字符串名称,LinkedHashMap的<字符串,
产品>产品){
这code = code;
this.name =名称;
this.products =产品;
}
公众的LinkedHashMap<字符串,产品与GT;的getProducts(){
返回this.products;
}
}
/ *** /
公共类产品{
公共字符串code;
公共字符串名称;
公共产品(){
}
公共产品(字符串code,字符串名称){
这code = code;
this.name =名称;
}
}
}
解决方案
经过一番调研和认真检查,我找到了解决办法是工作。
输出所需
下面是最终的code:
悦目code座
<! - LIST ::索具模型 - 决赛 - >
< DIV数据SLY-use.model =
$ {'com.tti.tticommons.service.models.LeadTimeTrendsModel@
rawJson = ws.JSON,configurationId ='leadtimetrends',web服务= WS}
数据狡猾,不折>
< DIV数据SLY-list.commodity =$ {model.getProductsList}数据SLY-展开>
< DIV CLASS =面板面板默认>
< DIV CLASS =面板标题>
< H3类=面板标题>吊带模型(名单) - $ {commodity.name @
上下文='HTML'}< / H3>
< / DIV>
< DIV CLASS =面板体数据SLY-list.product =
$ {commodity.products}>
< DIV CLASS =COL-MD-4 COL-SM-12行业
列表组无边界>
< DIV>
&其中;一类=>
$ {product.name}
&所述; / a取代;
< / DIV>
< / DIV>
< / DIV>
< / DIV>
< / DIV>
< / DIV>
吊带模型类
/ **吊带Model类* /
@Model(adaptables = {Resource.class,SlingHttpServletRequest.class})
公共类LeadTimeTrends {
私人列表<商品> productsList;
/ ** * /
公开名单<商品> getProductsList(){
名单<商品> productsList = buildProductsList(this.rawJson);
返回productsList;
}
/ ** * /
公开名单<商品> buildProductsList(字符串rawJson){
名单<商品>产品列表=新的ArrayList<商品>();
....业务逻辑....
......................
返回产品列表;
}
/ ** * /
公共类商品{
公共字符串code;
公共字符串名称;
公开名单<产品>产品;
公共无效商品(){
}
公共无效商品(字符串code,字符串名称,目录和LT;产品>的产品)
{
这code = code;
this.name =名称;
this.products =产品;
}
}
/ ** * /
公共类产品{
公共字符串code;
公共字符串名称;
公共产品(){
}
公共产品(字符串code,字符串名称){
这code = code;
this.name =名称;
}
}
I am not able to display values in a lit that are part of a POJO/SlingModel. Please help.
Desired Output
Commodity 1
Product 1, Product 2, Product 3
Commodity 2
Product 2, Product 4, Product 5
Sightly Code
<!-- LIST :: SLING MODEL -- FINAL -->
<div data-sly-
use.model="${'com.tti.tticommons.service.models.LeadTimeTrendsModel' @
rawJson=ws.JSON}" data-sly-unwrap>
<div data-sly-list.commodity="${model.getProductsList}">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Sling Model(List) - ${commodity.name @
context='html'}</h3>
</div>
<div class="panel-body" data-sly-
list.pr="${model.getProductsList.getProducts}">
<div class="col-md-4 col-sm-12 industry list-group no-
border">
<div>
<a class="">
${model.getProductsList.getProducts[pr]}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
My Sling Model Class
public class LeadTimeTrends {
private List<Commodity> productsList;
public List<Commodity> getProductsList() {
...business logic...
...........
return productsList;
}
public class Commodity {
public String code;
public String name;
public LinkedHashMap<String, Product> products;
public void Commodity(String code, String name, LinkedHashMap<String,
Product> products) {
this.code=code;
this.name=name;
this.products=products;
}
public LinkedHashMap<String, Product> getProducts() {
return this.products;
}
}
/***/
public class Product {
public String code;
public String name;
public Product() {
}
public Product(String code, String name) {
this.code=code;
this.name=name;
}
}
}
解决方案
After some research and careful checks i found the solution to be working.
Output as desired
Here's the final code:
Sightly code block
<!-- LIST :: SLING MODEL -- FINAL -->
<div data-sly-use.model =
"${'com.tti.tticommons.service.models.LeadTimeTrendsModel' @
rawJson=ws.JSON, configurationId='leadtimetrends', webService=ws}"
data-sly-unwrap>
<div data-sly-list.commodity="${model.getProductsList}" data-sly-unwrap>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Sling Model(List) - ${commodity.name @
context='html'}</h3>
</div>
<div class="panel-body" data-sly-list.product =
"${commodity.products}">
<div class="col-md-4 col-sm-12 industry
list-group no-border">
<div>
<a class="">
${product.name}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
Sling Model Class
/** Sling Model class */
@Model(adaptables={Resource.class, SlingHttpServletRequest.class})
public class LeadTimeTrends {
private List<Commodity> productsList;
/** */
public List<Commodity> getProductsList() {
List<Commodity> productsList = buildProductsList(this.rawJson);
return productsList;
}
/** */
public List<Commodity> buildProductsList(String rawJson){
List<Commodity> productList = new ArrayList<Commodity>();
....business logic....
......................
return productList;
}
/** */
public class Commodity {
public String code;
public String name;
public List<Product> products;
public void Commodity() {
}
public void Commodity(String code, String name, List<Product> products)
{
this.code=code;
this.name=name;
this.products=products;
}
}
/** */
public class Product {
public String code;
public String name;
public Product() {
}
public Product(String code, String name) {
this.code=code;
this.name=name;
}
}
这篇关于如何在SlingModel使用悦目列表中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!