2017-09-01 88 views
0

我的web應用程序是用Java(後端)編寫的。它使用Spring框架。javascript不接受我的c:out

現在,當我的Controller將模型返回到前端jsp時,我想從它的Hashmap中獲取一些值。

爲此,我使用JSTL和表達式語言庫。

<c:if test="${not empty model.ladungstraegerNummer}"> 
        yadcf.exFilterColumn(oTable, [[3, [' 
        <c:out value="${model.ladungstraegerNummer}"/> 
        ']]]); 
        </c:if> 

首先我檢查變量是空的(有時是),它被寫入的Javascript代碼後(yadcf是jQuery和數據表的頂部上的過濾器延伸)。

的C的結果是:出應該是這樣的:

yadcf.exFilterColumn(oTable, [[3, ['WNC402']]]); 

撇號是很重要的。我的代碼輸出是:

yadcf.exFilterColumn(oTable, [[3, [' 
          WNC402 
          ']]]); 

不知何故Javascript不接受這個字符串。

我編輯了我的問題,因爲它是錯誤的。 c:out工作和撇號我們在正確的地方。我想我的字符串中有一些whitspace,所以JS函數不能使用它。

+0

撇號不在c:out標記中,直接在JSP代碼中。所以它與c:out沒有任何關係。 –

回答

0

試試下面一個:

<c:if test="${not empty model.ladungstraegerNummer}"> 
         yadcf.exFilterColumn(oTable, [[3, [ 
         <c:out value="'${model.ladungstraegerNummer}'"/> 
         ]]]); 
         </c:if> 

JB Nizet的上述評論是有道理的。

0

我把我的代碼格式化了,現在看起來像這樣。我刪除了一些空格。

 <c:if test="${not empty model.ladungstraegerNummer}"> 
     yadcf.exFilterColumn(oTable, [[3, ['<c:out value="${model.ladungstraegerNummer}"/>']]]); 
     </c:if> 

輸出:

yadcf.exFilterColumn(oTable, [[3, ['WNC402']]]); 

謝謝你的努力的傢伙。