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

时间:2017-01-23 01:21:14

标签: javascript java jquery combobox el

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

我正在使用以下代码。如果我使用变量istatus它就不起作用了。

${claimNotificationForm.chattels[istatus].objectValue}

下面的工作就像..

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

如何在此处使用变量,以便基于istatus值,应该评估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" )
                })

1 个答案:

答案 0 :(得分:0)

您根本不需要使用[]。只需运行一个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>

编辑:

在了解了更多关于要求之后,我继续自己测试了这个。在这两种情况下,我的工作都非常好。所以问题是istatus正在评估一些超过列表大小的索引,或者我不知道。如果您运行<c:out value="${istatus}" />

,是否可以查看istatus的值是什么?

当我将一个随机值设置为变量istatus时,如果该值在列表的大小范围内,它会输出内容,如果它大于列表的大小,则会打印出空白。意思是它不会直接抛出错误。

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