gpt4 book ai didi

javascript - 使用 jquery 在自动完成组合框中使用 EL 表达式获取列表或数组中的所有元素

转载 作者:行者123 更新时间:2023-12-01 05:23:07 25 4
gpt4 key购买 nike

我想使用 el 表达式动态获取列表或数组中的所有元素。

我正在使用下面的代码。如果我使用变量 isstatus 它就不起作用。

${claimNotificationForm.chattels[istatus].objectValue}

下面的工作就像..

${claimNotificationForm.chattels[0].objectValue}
${claimNotificationForm.chattels[1].objectValue}

如何在此处使用变量,以便根据 isstatus 值计算 el 表达式。

下面是我使用它的jsp代码。

 _createAutocomplete: function() {

var x = this.element[0].id; //value is combobox-0
var status = x.substr(x.length - 1); // value is 0 which is in string
var istatus = parseInt(status); // converted to int


this.input = $( "<input>" )
.appendTo( this.wrapper )
.attr( "title", '<fmt:message key="page.claim.personalclaimnotification.injury.select_info" />' )
.val("${claimNotificationForm.chattels[0].objectValue}") //works fine with 0,1,2... I have to use 'istatus' here
.css({
color: function( index, value ) {
if (this.value == '<fmt:message key="page.claim.search.object.name" />') {
return "#777";
}
},
fontStyle: function( index, value ) {
if (this.value == '<fmt:message key="page.claim.search.object.name" />') {
return "italic";
}
},
width: "286px"
})
.attr("maxlength", 256)
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
.autocomplete({
delay: 0,
minLength: 3,
source: $.proxy( this, "_source" )
})

最佳答案

你根本不需要使用[]。只需运行 foreach 并放置 if/else 语句即可。

<c:forEach items="${ListName}" var="emp" varStatus="myIndex">
<c:choose>
<c:when test="${myIndex.index==1}">
//do something
</c:when>

</c:forEach>

编辑:

在了解了更多要求后,我自己进行了测试。我的在这两种情况下都工作得非常好。因此,问题要么是 isstatus 正在评估某个大于列表大小的索引,要么是我不知道。如果运行 <c:out value="${istatus}" />,您可以检查 isstatus 的评估值吗?

当我为变量 isstatus 设置一个随机值时,如果该值在列表的大小之内,它会打印出内容,如果它大于列表的大小,它会打印出空白。这意味着它不会直接抛出错误。

 <c:set var="istatus" value="${1}" />
...
<c:out value="${claimNotificationForm.chattels[istatus].objectValue}" /> //it prints something meaning it is working

关于javascript - 使用 jquery 在自动完成组合框中使用 EL 表达式获取列表或数组中的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41797998/

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