gpt4 book ai didi

javascript - 无法循环遍历 ember 模板中的 json 响应

转载 作者:行者123 更新时间:2023-11-29 17:01:34 25 4
gpt4 key购买 nike

我的json数组是

{
"object": {
"assignments": [
{
"assignmentId": 14706368,
"sectionId": 0,
"assignmentTitle": "file attachment A",
"assignmentStartDate": "01/01/1900",
"assignmentStartTime": "01:00AM",
"assignmentDueDate": "01/01/2100",
"assignmentDueTime": "01:00AM",
"isMarathonChain": "No",
"assignmentTimeLimit": 0,
"assignmentTimeRemaining": "0",
"marathonAssignmentStatus": "MARATHON_NOT_ASSOCIATED",
"showAssignmentAttemptsAndPasswordDetails": false,
"assignmentAttemptsTaken": 0,
"assignmentAttemptsAllowed": "1",
"showPasswordForm": false,
"isStartAssignment": true,
"isResumeAssignment": false,
"isSubmitAssignment": false,
"passwordRequired": false,
"isConvertToGeniusEnabled": false,
"draftNumber": 0,
"studentExceptionExistsForDueDate": false,
"isPastUploadDate": false,
"showMarathonPrerequisiteInfo": false
}
],
"sections": [
{
"sectionId": 241409387,
"courseId": 241409386,
"sectionName": "Section01"
}
],
"courses": [
{
"courseId": 241409386,
"courseName": "Tricon.Connect_01",
"showDiscipline": false
}
],
"users": [
{
"userId": 1000321061,
"firstName": "Ragu �������&^&",
"lastName": "+#@)()Tricon �^^������",
"userType": "S"
}
],
"returnLMS": [
{
"returnUrl": "bb"
}
]
}
}

我想遍历假设赋值我正在我的循环模型模板中写这个

{{#each obj in model.object}}
<tr>
{{#each assign in obj.assignments }}
<td>
{{assign.assignmentId} <br />{{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}

但我没有得到输出。我的循环仅在第一行失败。我必须使用这些值来匹配某些条件并显示信息。

最佳答案

这现在通过使用模板中的 {{each-in}} 助手来处理。您可以阅读更多相关信息 here但我会尝试一个适用于您的案例的示例

{{#each-in model.object as |key values|}}
<tr>
{{#each values as |assign|}}
<td>
{{assign.assignmentId} <br /> {{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}

尽管您的示例看起来更像是您只想遍历分配,因为您在内部 each 中使用特定于分配的代码,所以看起来就像这样

{{#each model.object.assignments as |values|}}
<tr>
{{#each values as |assign|}}
<td>
{{assign.assignmentId} <br /> {{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}

但是,如果您确实想要遍历每个键并根据当前正在处理的 拥有不同的模板,您可以这样做:

{{#each-in model.object as |key values|}}
{{#if (eq key 'assignments')}}
<tr>
{{#each values as |assign|}}
<td>
{{assign.assignmentId} <br /> {{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/if}}
{{#if (eq key 'sections')}}
<tr>
{{#each values as |section|}}
<td>
{{section.sectionId} <br /> {{section.sectionName}
</td>
{{/each}}
</tr>
{{/if}}
{{/each}}

当然,这取决于您以及您要通过您的应用程序实现的目标😂另外,顺便说一下,这个例子使用了ember-truth-helpers。如果您想执行我示例中的那些 {{#if}} block ,这将非常有用。

关于javascript - 无法循环遍历 ember 模板中的 json 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27150006/

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