2016-05-17 70 views
1

我想用我的ui-typeahead輸入在下面的對象列表中排序majorBy。orderBy與ui-typeahead在對象中的值

[ 
    { 
     name: 'London (LHR)', 
     code: 'LHR', 
     country: 'GB', 
     major: 1 
    }, 
    { 
     name: 'Gatwick (LGW)', 
     code: 'LGW', 
     country: 'GB', 
     major: 0 
    } 
] 

<input 
    type="text" 
    name="destination" 
    uib-typeahead="airport as airport.name for airport in getAirports($viewValue) | filter:$viewValue | orderBy:airport.major | limitTo:8" 
/> 

我嘗試了「major」和「airport.major」,如上例所示。主要反映機場是否是一個大機場。例如,倫敦希思羅機場將是1,而蓋特威克機場將是0.

getAirports()創建機場對象,因爲輸出需要對機場名稱進行一些驗證。

orderBy沒有效果,任何人都可以發現我要去哪裏錯了嗎?

回答

3

對我而言,工作的價值在於我想用單引號排序。所以根據你的例子,這將是:

<input type="text" name="destination" 
    uib-typeahead="airport.name for airport in getAirports($viewValue) | filter:$viewValue | orderBy:'major' | limitTo:8" 
/>