2013-07-16 42 views
0

使用youtube json api的Im,它返回viewcount作爲一個字符串,但我需要將它排序爲一個數字。我怎麼能不通過整個模型並將字符串轉換爲整數?Angular - orderBy string as number

JSON片斷

yt$hd: Object 
yt$statistics: Object 
favoriteCount: "0" 
viewCount: "1443" 
__proto__: Object 

和IM invoiking排序像

orderBy:'yt$statistics.viewCount' 

回答

1

不與角度說firmilar,但我認爲orderBy參數可以採用功能到位像Lo-Dash does with its `sortBy() function字符串。在這種情況下,你可能需要這樣的東西:

orderBy: function(obj){ 
    return ~~obj.yt$statistics.viewCount 
}