gpt4 book ai didi

javascript - 我们如何根据 AngularJS 中的实际对象数组自定义分组

转载 作者:行者123 更新时间:2023-12-03 03:24:34 28 4
gpt4 key购买 nike

我必须根据以下对象数组中的 standardID 创建自定义分组顺序:

实际数组:

var test=[
{ID: "91",Name: "sgtue", standardID: "1"},
{ID: "41",Name: "asdfasdf", standardID: "2"},
{ID: "5", Name: "credd", standardID: "2"},
{ID: "2",Name: "dddawer", standardID: "2"},
{ID: "2",Name: "dsfadf", standardID: "3"},
{ID: "275", Name: "xcvcvc", standardID: "201"}
]

预期结果:我只想将 standardID 分组,例如 1,3,2,2,2,201

[
{ID: "91",Name: "sgtue", standardID: "1"},
{ID: "2",Name: "dsfadf", standardID: "3"},
{ID: "275", Name: "xcvcvc", standardID: "201"},
{ID: "41",Name: "asdfasdf", standardID: "2"},
{ID: "5", Name: "credd", standardID: "2"},
{ID: "2",Name: "dddawer", standardID: "2"}
]

请帮我解决这个问题。

最佳答案

您可以尝试此原型(prototype)按属性对象自定义排序:

var test=[{ID: "91",Name: "sgtue", standardID: "1"},
{ID: "41",Name: "asdfasdf", standardID: "2"},
{ID: "5", Name: "credd", standardID: "2"},
{ID: "2",Name: "dddawer", standardID: "2"},
{ID: "2",Name: "dsfadf", standardID: "3"},
{ID: "275", Name: "xcvcvc", standardID: "201"}
];

https://codepen.io/anon/pen/KXNpMZ?editors=1112

@萨蒂什

已更新,按索引数组引用排序:

https://codepen.io/anon/pen/RLoZOX?editors=1112

关于javascript - 我们如何根据 AngularJS 中的实际对象数组自定义分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46389698/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com