我有以下对象,其中包含2个固定属性(OrderId和Purchasedate,以及一个attribues数组。我尝试使用orderBy选项将其放入ng-repeat。前2个属性(OrderId和PurchaseDate)工作正常通过单击标题来应用排序。但是我没有使用它来处理第3个属性,依此类推。
表格中显示的行是正确的。
对象看起来像 例如
$scope.orders;
[
{ OrderId: "P888291", PurchaseDate : "2016-12-02",
Items: { elt : [ { Name: "City", Value: "New York"}, { Name: "Street", Value: "Broadway 5" }, { Name: "Country", Value: "USA" } ] } },
{ OrderId: "P334498", PurchaseDate : "2016-11-02",
Items: { elt : [ { Name: "City", Value: "London" }, { Name: "Street", Value: "WestMinister 3" }, { Name: "Country", Value: "Great Brittain" } ] } },
{ OrderId: "G393383", PurchaseDate : "2016-11-28",
Items: { elt : [ { Name: "City", Value: "Milan" }, { Name: "Street", Value: "Pizza 8" }, { Name: "Country", Value: "Italy" } ] } },
{ OrderId: "P978381", PurchaseDate : "2015-05-25",
Items: { elt : [ { Name: "City", Value: "Seattle" }, { Name: "Street", Value: "Houston 9" }, { Name: "Country", Value: "US" } ] } },
{ OrderId: "P983394", PurchaseDate : "2015-06-05",
Items: { elt : [ { Name: "City", Value: "Amsterdam" }, { Name: "Street", Value: "Damrak 5" }, { Name: "Country", Value: "Netherlands" } ] } },
{ OrderId: "G678994", PurchaseDate : "2015-04-01",
Items: { elt : [ { Name: "City", Value: "The Hague" }, { Name: "Street", Value: "Markt 22" }, { Name: "Country", Value: "Netherlands" } ] } },
{ OrderId: "P128994", PurchaseDate : "2016-12-04",
Items: { elt : [ { Name: "City", Value: "The Hague" }, { Name: "Street", Value: "Plein 7" }, { Name: "Country", Value: "Netherlands" } ] } },
];
请告知并输入代码:
http://www.w3schools.com/code/tryit.asp?filename=FAG7BWVK8BYH
答案 0 :(得分:0)
您可以尝试使用自定义过滤器逻辑。(https://docs.angularjs.org/api/ng/filter/orderBy) 例如:
JS:
None
HTML:
None
如果您需要非常具体的订购行为,您可以编写自己的过滤器(尽管orderBy应该足以满足大多数用例)。您可能知道可以将多个过滤器链接在一起,因此添加自定义过滤器功能并不会强制您使用搜索对象删除以前的过滤器(它们将无缝地协同工作)。