AngularJS orderBy未按预期工作

时间:2015-05-07 14:47:43

标签: javascript html json angularjs

我是Angular的新手,我使用$ http.jsonp从joomla网站获取一些json数据。

我只是在拉类别,即

<xsl:function name="wd:gePhone">
        <xsl:param name="phone_number" />
        <xsl:if test="$phone_number !=' '" >
            <xsl:value-of select="normalize-space(replace(replace(replace(replace(replace(replace($phone_number,'-',''),'/',''),' ',''),'\)',''),'\(',''),'\+1',''))"/>
        </xsl:if>
    </xsl:function>

我正在尝试使用orderBy来组织这些类别:| ORDERBY: ' - 编号'“

这可行,但以奇怪的方式,输出为:1,10,100,2,23,200,3,34,300等。

显然不正确。

有没有解决这个问题?

1 个答案:

答案 0 :(得分:1)

您需要更改服务器端的响应,因为您正在对数组进行排序-id正在根据string比较进行排序。将该字符串更改为数字(整数)将更有意义。而是使用过滤器并将其转换为整数然后进行排序,这不会被认为是一种好方法。

<强> JSON

{
  id: 89, //<-- this should be number instead of string
  name: "Labour",
  description: "&lt;p&gt;{module Labour Featured Stories}&lt;/p&gt;",
  image: "/media/k2/categories/",
  language: "*",
  parent: "87"
}

{
  id: 90, //<-- this should be number instead of string
  name: "International",
  description: "&lt;p&gt;{module International Featured Stories}&lt;/p&gt;",
  image: "/media/k2/categories/",
  language: "*",
  parent: "87"
}