漂亮的jstl c:set模拟 [英] Sightly jstl c:set analog
问题描述
在jsp上,我可以编写以下代码:
On jsp I can write following code:
<c:set var="salary" value="${object.salary}"/>
然后在代码中我可以使用 $ {salary}
变量
and then in code I can use ${salary}
variable
您能帮忙重写它吗?
PS
我尝试过这个:
<div data-sly-use.salary="MySalary">
<div data-sly-use.product="MyBean" data-sly-unwrap>
{
<ul data-sly-list="${product.specifications}" data-sly-unwrap>
"${item.sku ? item.sku : 'product'}" : "${item.label} ${item.value}"<div data-sly-test="${!itemList.last}" data-sly-unwrap>,</div>
</ul>
}
</div>
</div>
<div data-bla-bla="${salary}"></div>
但是我看到编译错误
推荐答案
您没有在Sightly中分配变量的功能。可能的最大值是比较值,否则您的所有逻辑都会进入Java或JavaScript Use-API
类。
You don't have the feature of assigning variables in Sightly. The maximum that is possible is comparing values, else all your logic goes into the Java or JavaScript Use-API
classes.
使用数据狡猾使用
时,提供的值必须为
When you are using data-sly-use
, the value provided must either be
- 扩展
WCMUse
类或实现Use
接口或 - 定义了使用类的JavaScript文件。
的Java类
- Java class that extends the
WCMUse
class or implements theUse
interface or - JavaScript file that defines the use class.
因此,当的值时会收到编译错误数据狡猾使用
都不是以上两个。
Hence you receive a compilation error when the value of data-sly-use
is neither of the above two.
但是,我可以为您的问题提供一个解决方法,尽管我不会建议使用相同的。
您可以使用 data-sly-test
并为其指定一个变量名,以后可以在其他地方使用。
However, I can suggest a workaround for your question, though I wouldn't recommend using the same.
You can make use of data-sly-test
and assign a variable name to that, which can later be used elsewhere.
例如。
<div data-sly-test.salary="MySalary"></div>
<div>
<div data-sly-use.product="MyBean" data-sly-unwrap>
{
<ul data-sly-list="${product.specifications}" data-sly-unwrap>
"${item.sku ? item.sku : 'product'}" : "${item.label} ${item.value}"<div data-sly-test="${!itemList.last}" data-sly-unwrap>,</div>
</ul>
}
</div>
</div>
<div data-bla-bla="${salary}"></div>
这篇关于漂亮的jstl c:set模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!