【问题标题】:Angular - orderBy string as numberAngular - orderBy 字符串作为数字
【发布时间】:2013-07-16 23:35:46
【问题描述】:

我正在使用 youtube json api,它将查看次数作为字符串返回,但我需要将其排序为数字。如果不通过整个模型并将字符串转换为整数,我怎么能做到这一点?

json-p

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

我正在调用排序

orderBy:'yt$statistics.viewCount'

【问题讨论】:

    标签: javascript jquery html angularjs underscore.js


    【解决方案1】:

    与 Angular 不一样,但我假设orderBy 参数可以使用函数代替Lo-Dash does with its `sortBy() function 之类的字符串。在这种情况下,您可能需要这样的东西:

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

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2015-08-25
      • 2015-04-22
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      相关资源
      最近更新 更多