Angular - orderBy string as number

时间:2013-07-16 23:35:47

标签: javascript jquery html5 angularjs underscore.js

我使用youtube json api并将viewcount作为字符串返回,但我需要将其排序为数字。如果不通过整个模型并将字符串转换为整数,我怎么能这样做?

json片段

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

和im invoiking sort like

orderBy:'yt$statistics.viewCount'

1 个答案:

答案 0 :(得分:1)

与Angular不一样,但我认为orderBy参数可以取代Lo-Dash does with its `sortBy() function之类的字符串。在这种情况下,你可能想要这样的东西:

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