我正在尝试访问每个问题的第一个组件中的名称,似乎无法解决这个问题。组件数组中只有一个项目。在这种情况下,它应该返回“KBR”这是我的代码:
<script>
// Gets the data related to items added in sprint pi-19.3
$(document).ready(function() {
$.getJSON("./json/PI-19/taxonomyAddedAfterSprintStart.19.3.json", function(data_add) {
var jira_data_add = '';
$.each(data_add.issues, function(key, val){
jira_data_add += '<tr>';
jira_data_add += '<td>'+val.key+'</td>';
jira_data_add += '<td>'+val.fields.issuetype.name+'</td>';
jira_data_add += '<td>'+val.fields.summary+'</td>';
jira_data_add += '<td class="centered-cell">'+val.fields.customfield_10013+'</td>'; // Story Points Custom Field
jira_data_add += '<td class="centered-cell">'+val.fields.status.name+'</td>';
jira_data_add += '<td class="centered-cell">'+val.fields.components.name+'</td>';
});
jira_data_add += '</tr>';
$('#sprint-items-added-pi-nineteen-c').append(jira_data_add);
});
});
</script>
这是JSON
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "1286516",
"self": "https://xxx",
"key": "TAXY-662",
"fields": {
"components": [
{
"self": "https://xxx",
"id": "40920",
"name": "KBR"
}
],
}
我也试过了:
jira_data_add += '<td class="centered-cell">'+val.fields.components[0].name+'</td>';
这不起作用 - 我得到了未定义的回复
我也试过了:
jira_data_add += '<td class="centered-cell">'+val.fields.components["name"]+'</td>';
我再次在表格中未定义