gpt4 book ai didi

javascript - ng-repeat 按特定顺序显示 html

转载 作者:行者123 更新时间:2023-11-28 19:51:19 25 4
gpt4 key购买 nike

我收到了 json 消息:

我正在尝试按特定顺序将 json 消息加载到 html 中。

你会在json消息中找到position值,数组中的第一个元素:0表示顺序。

有时,json 消息是乱序的,与示例不同。

有没有办法将json消息按顺序输出在html中:0,1,2,3。

HTML部分是:

<div class="container">
<div ng-repeat="question in questions">
<div class="row">
// load the question in increase order
</div>
</div>
</div>

Json 消息:

[ { "Question" : { "description" : { "default" : "hello" },
"options" : [ { "value" : { } } ],
"title" : { "default" : "hello world" }
},
"Selection" : "text",
"position" : [ 0,
12,
0
]
},
{ "Question" : { "description" : { "default" : "hello 2" },
"options" : [ { "value" : { } } ],
"title" : { "default" : "hello 2" }
},
"Selection" : "paragraph",
"position" : [ 1,
12,
0
]
},
{ "Question" : { "description" : { "default" : "hello 3" },
"options" : [ { "value" : { "default" : "1" } },
{ "value" : { "default" : "2" } }
],
"title" : { "default" : "hello 3" }
},
"Selection" : "radio",
"position" : [ 2,
12,
0
]
},
{ "Question" : { "description" : { "default" : "hello 4" },
"options" : [ { "value" : { "default" : "check11" } },
{ "value" : { "default" : "check22" } }
],
"title" : { "default" : "hello 4" }
},
"Selection" : "checkbox",
"position" : [ 3,
12,
0
]
},
{ "Question" : { "description" : { "default" : "hello 5" },
"options" : [ { "value" : { "default" : "list1" } },
{ "value" : { "default" : "list2" } }
],
"title" : { "default" : "hello 5" }
},
"Selection" : "list",
"position" : [ 4,
12,
0
]
}
]

最佳答案

您需要将位置数组中的第一项指定给 orderBy 过滤器:

ng-repeat="question in questions | orderBy:'position[0]'"

Fiddle

关于javascript - ng-repeat 按特定顺序显示 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23407492/

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