我的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"
}
]
}
}
我希望循环调用assignmet值 我正在我的模板中写这个用于循环模型
{{#each obj in model.object}}
<tr>
{{#each assign in obj.assignments }}
<td>
{{assign.assignmentId} <br />{{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}
但我没有得到输出。我的循环仅在第一行失败。 我必须使用这些值来匹配某些条件和显示信息。
答案 0 :(得分:3)
现在可以使用模板中的var
帮助程序来处理。您可以阅读更多相关信息here,但我会尝试一个适合您案例的示例
SELECT DISTINCT data.*
FROM
(
SELECT t2.*
FROM [ActualTable1Name] AS t1
INNER JOIN [ActualTable2Name] AS t2 ON t1.NR = t2.NR
UNION ALL
SELECT t2.*
FROM [ActualTable1Name] AS t1
INNER JOIN [ActualTable2Name] AS t2 ON SUBSTRING(t1.Text, 6, LEN(t1.Text) - 5) = t2.NR
) AS data
虽然你的例子看起来更像你只想循环分配,因为你在内部使用的是赋值特定代码,所以看起来就像这样
{{each-in}}
但是,如果您确实想要遍历每个键并根据您当前正在处理的键而拥有不同的模板,则可以执行以下操作:
{{#each-in model.object as |key values|}}
<tr>
{{#each values as |assign|}}
<td>
{{assign.assignmentId} <br /> {{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}
但是当然这取决于你和你正在尝试用你的应用程序实现的东西顺便说一句,顺便说一句,这个例子使用了ember-truth-helpers,如果你想做的事情非常有用我的示例中的那些{{#each model.object.assignments as |values|}}
<tr>
{{#each values as |assign|}}
<td>
{{assign.assignmentId} <br /> {{assign.assignmentTitle}
</td>
{{/each}}
</tr>
{{/each}}
块。
答案 1 :(得分:2)
根据您提供的示例JSON,以下行是您的问题:
{{#each obj in model.object}}
似乎model.object
是一个Javascript对象,而不是一个数组。 each
循环只迭代或数组(可能是类似数组的对象),而不是任意Javascript对象。如果要迭代对象的键和值,则必须创建一个计算属性来执行此操作。