2015-10-02 16 views
0

我已安裝最新版本的Domino上運行的最新擴展庫。我正在使用一個簡單的列表框與來自DBColumn(它的工作來填充列表框)的值。嘗試使用Select2獲取列表框的值

但是,我似乎無法獲得listBox的選定值。我在網絡上打了一會兒,發現了幾個不同的東西,我嘗試過的不成功。然後我開始閱讀有關安裝其他庫等現在我感到困惑。以下是我的代碼。我想要做的就是從列表框中獲取選定的值,但我真的想使用select2功能來搜索列表框。有人能指出我在正確的方向上如何在選擇值變化時獲得選定的值嗎?

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:bx="http://www.openntf.org/xsp/bootstrap"> 

<xp:scriptBlock id="scriptBlock2"> 
<xp:this.value> 
<![CDATA[ 
    $(document).ready(
    function() { x$("#{id:listBoxProperties}").select2() 
     .on("change", function(e) { XSP.partialRefreshPost(
     "#{id:computedField2}"); 
     } 
    } 
); 
]]> 
</xp:this.value> 
</xp:scriptBlock> 

    <xp:panel> 
     <xp:listBox id="listBoxProperties" value="#{viewScope.selectedProperty}" 
      style="width:250px"> 
      <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:listOfProperties = @DbColumn(@DbName(), 'vwAuditDocsByPropertyNo', 1); 
if(@IsError(listOfProperties)) 
     "Error looking up properties: " + listOfProperties; 
    listOfProperties; 
    }]]></xp:this.value> 
      </xp:selectItems> 
      <xp:eventHandler event="onchange" submit="true" 
       refreshMode="complete"> 
      </xp:eventHandler></xp:listBox> 
     <bx:select2PickerCombo id="select2Property" 
      for="listBoxProperties" placeHolder="-Select a Property-" 
      binding="#{javascript:viewScope.selectedProperty}"> 
     </bx:select2PickerCombo> 
     <xp:br></xp:br> 
     <xp:text escape="true" id="computedField1" 
      value="#{javascript:viewScope.selectedProperty;}"> 
     </xp:text> 
     <xp:text escape="true" id="computedField2"> 
      <xp:this.value><![CDATA[#{javascript:getComponent("listBoxProperties").getValue()}]]></xp:this.value> 
     </xp:text> 
    </xp:panel> 
</xp:view> 
+0

您是否試圖從客戶端或服務器端獲取值? –

+0

好問題。我想設置一個viewscope var,它將在用戶從列表框 – Bitwyse1

回答

0

我已經測試您的方案,並可以驗證使用BX當lixtBox的onchange事件不火:select2PickerCombo樣式列表框作爲選擇二控制。如果刪除使用bx:select2PickerCombo,則onchange事件會按預期觸發。這裏有一個簡單的例子(不使用BX的:select2PickerCombo):

<xp:listBox id="listBoxProperties" value="#{viewScope.selectedProperty}" style="width:250px"> 
    <xp:selectItems> 
     <xp:this.value><![CDATA[#{javascript:["1","2","3"]}]]></xp:this.value> 
    </xp:selectItems> 
    <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="refreshField"></xp:eventHandler> 
</xp:listBox> 
<!--<bx:select2PickerCombo id="select2Property" for="listBoxProperties" placeHolder="-Select a Property-" binding="#{javascript:viewScope.selectedProperty}"></bx:select2PickerCombo>--> 

<xp:text escape="true" id="refreshField" value="#{javascript:viewScope.selectedProperty;}"></xp:text> 

您需要手動選擇二添加到您的列表框來獲取onchange事件工作。請參閱此答案以獲取更多詳細信息:Bootstrap4XPages plugin: how to catch a change event with Select2 Picker?

+0

Per中選擇一個選項時設置視圖類別過濾器,這個例子對我來說沒有意義。無論如何,要爲我貶低一點點? \t \t \t <![CDATA [ $(文件)。就緒( 函數(){X $( 「#{ID:listBoxProperties}!」).select2( ) 。對( 「變化」,函數(E){XSP.partialRefreshPost( 「#{ID:panelPropertyList}」);} } ); ]]> Bitwyse1

+0

我無法添加所有代碼。這裏是聯繫在一起的SELECT2 列表框 <![CDATA [#{javascript:listOfProperties = @DbColumn(@DbName(),'vwAuditDocsByPropertyNo',1); if(@IsError(listOfProperties)) \t \t「查找屬性時出錯:」+ listOfProperties; \t listOfProperties; }]]> Bitwyse1

相關問題