用户故事对象上的 TestCases 字段是测试用例的集合,您需要遍历该集合以获取 FormattedID 和集合中各个元素的其他字段。这是代码:
var rallyDataSource = null;
var iterDropdown = null;
var table = null;
function showUserStoriesTable(results) {
for (var i=0; i < results.stories.length; i++) {
var t = " ";
if (results.stories[i].TestCases){
console.log(results.stories[i].TestCases.length);
for(var j = 0; j < results.stories[i].TestCases.length; j++){
t += " ";
t += results.stories[i].TestCases[j].FormattedID;
}
results.stories[i].TestCases=t;
}
}
var tableConfig = {
columnKeys : ['FormattedID', 'Name', 'TestCases' ],
columnWidths : ['80px', '360px', '400px']
};
table = new rally.sdk.ui.Table(tableConfig);
table.addRows(results.stories);
table.display(document.getElementById('stories'));
}
function onIterationSelected() {
if(table) {
table.destroy();
}
var queryConfig = {
type : 'hierarchicalrequirement',
key : 'stories',
fetch: 'FormattedID,Name,TestCases',
query: '(Iteration.Name = "' + iterDropdown.getSelectedName() + '")',
order: 'Rank'
};
rallyDataSource.findAll(queryConfig, showUserStoriesTable);
}
function onLoad() {
// rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__','__PROJECT_OID__','__PROJECT_SCOPING_UP__','__PROJECT_SCOPING_DOWN__');
rallyDataSource = new rally.sdk.data.RallyDataSource('111111','222222','false','false'); //IF RUNNING OUSIDE OF RALLY USE OIDs
var iterConfig = {};
iterDropdown = new rally.sdk.ui.IterationDropdown(iterConfig, rallyDataSource);
iterDropdown.display(document.getElementById("iterationDiv"), onIterationSelected);
}
rally.addOnLoad(onLoad);