如何使用 Sightly 在 SlingModel 列表中显示值
How to display values in a List of a SlingModel using Sightly
我无法在属于 POJO/SlingModel 的灯光中显示值。请帮忙
期望输出
商品1
产品 1、产品 2、产品 3
商品2
产品 2、产品 4、产品 5
视觉代码
<!-- 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>
我的吊带型号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;
}
}
}
经过一些研究和仔细检查后,我发现该解决方案有效。
按需输出
这是最终代码:
好看的代码块
<!-- 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>
吊带型号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;
}
}
我无法在属于 POJO/SlingModel 的灯光中显示值。请帮忙
期望输出
商品1
产品 1、产品 2、产品 3
商品2
产品 2、产品 4、产品 5
视觉代码
<!-- 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>
我的吊带型号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;
}
}
}
经过一些研究和仔细检查后,我发现该解决方案有效。
按需输出
这是最终代码:
好看的代码块
<!-- 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>
吊带型号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;
}
}