2014-11-21 134 views
0

我想在ng-repeat中使用Wijimo自動完成指令,但我可以成功綁定到數據源我無法爲特定實例設置範圍 - 在指令中選擇的值是爲範圍內的所有實例設置的。Wijimo 5 AngularJS - ng重複和自動完成指令問題

它是使用重複輸入控件時經典的ng-repeat問題。

我不確定它的方式wj-auto-complete指令設置範圍上的哪些屬性。

所以這適用於1個實例和一個ng-repeat內的多個實例(但設置相同的值)。

<wj-auto-complete 
       text="selectedHotel" 
       items-source="limo.hotelData" 
       placeholder="Hotel" 
       display-member-path="address" 
       max-items="50"/> 
      </div> 
      <p>{{selectedHotel || json}}</p> 

我曾嘗試以下

<div ng-repeat="flight in flights"> 
    <wj-auto-complete    
    text="flight.from"      
    items-source="limo.hotelData"      
    placeholder="Hotel" 
    display-member-path="address"      
    max-items="50"/> 
</div> 

,但沒有喜悅。

它看起來像文本屬性是用選定的值設置?雖然房產價值有點奇怪。

回答

2

ComboBox和AutoComplete控件都有一個「text」屬性,用於獲取或設置控件當前顯示的文本,還有一個「selectedValue」屬性,用於獲取或設置當前選定的值。除了用戶正在鍵入並且不完整的文本與有效選擇列表中的任何項目不匹配之外,這兩者通常是匹配的。

這個小提琴顯示瞭如何使用「selectedValue」屬性適用於ComboBox和AutoComplete。我希望這是有用的:

http://jsfiddle.net/Wijmo5/8p94jo6q/

<table class="table table-condensed"> 
    <thead> 
     <th>ID</th> 
     <th>Country</th> 
     <th>AutoComplete</th> 
     <th>ComboBox</th> 
    </thead> 
    <tbody> 
     <tr ng-repeat="item in data"> 
      <td> 
       {{item.id}} 
      </td> 
      <td> 
       {{item.country}} 
      </td> 
      <td> 
       <wj-auto-complete 
        items-source="countries" 
        selected-value="item.country" 
        placeHolder="country" 
        required="false"> 
       </wj-auto-complete> 
      </td> 
      <td> 
       <wj-combo-box 
        items-source="countries" 
        selected-value="item.country" 
        placeHolder="country" 
        required="false"> 
       </wj-combo-box> 
      </td> 
     </tr> 
    </tbody> 
</table>