我正在尝试使用Rally sdk编写一些js来获取与项目相关联的团队成员列表。我的下拉框将包含我当前的项目以及其子项目列表。选择后,它将显示所选项目的团队成员列表。
到目前为止,我尝试过两种方式:
一个没有所有子项目的相当简单的方法,在这里我只获得当前项目的第一级子项目(不递归获取所有子项目)。
递归获取当前项目的所有子项目。
到现在为止,我只能完成(1)并在下拉列表中获得所有第一级子项目(尚未进一步获得团队成员)。但是,我遇到了一些问题方法(2)。
使用递归,我可以获取数组中的所有项目并正确推送它,但列表不会显示在下拉框中。请注意,我正在通过在Rally中将其作为自定义html进行复制粘贴来测试我的代码。我也没有任何错误来理解可能出错的地方。
这是我的方法1:
<script type="text/javascript">
var projects_array = new Array();
var child_project = new Array();
function onLoad() {
//Add app code here
loadProjectDropdown();
}
function loadProjectDropdown()
{
var rallyDataSource = new rally.sdk.data.RallyDataSource("__WORKSPACE_OID__","__PROJECT_OID__","__PROJECT_SCOPING_UP__","__PROJECT_SCOPING_DOWN__");
var queryArray = new Array();
queryArray.push({
key:"projects",
type:"project",
fetch: "Children,Name",
query: rally.sdk.util.Query('ObjectID = "' + '__PROJECT_OID__' + '"')
});
rallyDataSource.findAll(queryArray,processQueryArray);
}
function processQueryArray(results){
var data = new Array();
var project = results.projects;
/*
*
* This is just a test from Rohan
*/
var all_projects = new Array();
data.push({label: project[0].Name, value: project[0].Name});
if(project[0].Children != null)
{
for(var i=0;i<project[0].Children.length;i++)
{
//document.write("Number "+i+" "+project[0].Children[i].Name);
data.push({label: project[0].Children[i].Name, value: project[0].Children[i].Name});
}
}
//pass the first parent project to a function that recursively gets all child projects.
//all_projects = get_child_recursively(project[0]);
//document.write(JSON.stringify(all_projects));
/*for(var i=0;i<all_projects.length;i++)
{
data.push({label: all_projects[i].Name, value: all_projects[i].Name});
//document.write(JSON.stringify(all_projects[i]));
//data.push({label: all_projects[i].Name, value: all_projects[i].Name});
}*/
projectDropDown = new rally.sdk.ui.basic.Dropdown({label: "Select Project", items: data, width: 250});
projectDropDown.display("projectDropDown",projectDropDownChanged);
}
//Recursive algorithm to get all child projects of a parent project
//Nothing wrong with this code, I have commented this function for appraoch 1
function get_child_recursively(parent_project)
{
//check if this project is in array
projects_array.push(parent_project);
if(parent_project.Children.length>0)
{
for(var i=0;i<parent_project.Children.length;i++)
{
if(child_project.indexOf(parent_project.Children[i])<=-1)
child_project.push(parent_project.Children[i]);
}
for(var i=0;i<child_project.length;i++)
{ var temp = child_project[i];
child_project.splice(i,1);
get_child_recursively(temp);
}
}
else{
return;
}
if(child_project.length==0 || child_project.length==1){
return projects_array;
}
}
function projectDropDownChanged(dropdown,eventArgs){
projectName = eventArgs.value;
//loadTeamMembersDropDown();
}
function loadTeamMembersDropDown(){
var rallyDataSource = new rally.sdk.data.RallyDataSource("__WORKSPACE_OID__","__PROJECT_OID__","__PROJECT_SCOPING_UP__","__PROJECT_SCOPING_DOWN__");
var rallyqueryObject = {
key: "projects",
type: "project",
fetch: "TeamMembers,Name",
query: rally.sdk.util.Query('Name = "' + projectName + '"' ),
order: "Name desc"
};
rallyDataSource.findAll(rallyqueryObject,processTeamMemberResult);
}
function processTeamMemberResult(results){
var teamMember = results.projects;
}
rally.addOnLoad(onLoad);
</script>
<style type="text/css">
.teamApp {
/* Add app styles here */
}
</style>
方法2:方法2是当我激活我的递归函数并且它也给我正确的数组时,我然后使用data.push({label: all_projects[i].Name, value: all_projects[i].Name});
如在代码中所见,以正确的格式构建数据数组内的数据,然后将其传递给sdk.ui.basic.Dropdown
构造函数。但由于某种原因,我在拉力赛中运行时没有输出。我甚至没有在拉力赛中显示下拉框,只是一个空白的应用程序。
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!--App information-->
<meta name="Name" content="App: TeamApp"/>
<meta name="Version" content="1.0"/>
<meta name="Vendor" content=""/>
<!--Include SDK-->
<script type="text/javascript" src="/apps/1.29/sdk.js"></script>
<script type="text/javascript">
var projects_array = new Array();
var child_project = new Array();
function onLoad() {
//Add app code here
loadProjectDropdown();
}
function loadProjectDropdown()
{
var rallyDataSource = new rally.sdk.data.RallyDataSource("__WORKSPACE_OID__","__PROJECT_OID__","__PROJECT_SCOPING_UP__","__PROJECT_SCOPING_DOWN__");
var queryArray = new Array();
queryArray.push({
key:"projects",
type:"project",
fetch: "Children,Name",
query: rally.sdk.util.Query('ObjectID = "' + '__PROJECT_OID__' + '"')
});
rallyDataSource.findAll(queryArray,processQueryArray);
}
function processQueryArray(results){
var data = new Array();
var project = results.projects;
/*
*
* This is just a test from Rohan
*/
var all_projects = new Array();
//data.push({label: project[0].Name, value: project[0].Name});
/*if(project[0].Children != null)
{
for(var i=0;i<project[0].Children.length;i++)
{
//document.write("Number "+i+" "+project[0].Children[i].Name);
data.push({label: project[0].Children[i].Name, value: project[0].Children[i].Name});
}
}*/
//pass the first parent project to a function that recursively gets all child projects.
all_projects = get_child_recursively(project[0]);
//document.write(JSON.stringify(all_projects));
for(var i=0;i<all_projects.length;i++)
{
data.push({label: all_projects[i].Name, value: all_projects[i].Name});
//document.write(JSON.stringify(all_projects[i]));
//data.push({label: all_projects[i].Name, value: all_projects[i].Name});
}
projectDropDown = new rally.sdk.ui.basic.Dropdown({label: "Select Project", items: data, width: 250});
projectDropDown.display("projectDropDown",projectDropDownChanged);
}
//Recursive algorithm to get all child projects of a parent project
function get_child_recursively(parent_project)
{
projects_array.push(parent_project);
if(parent_project.Children.length>0)
{
for(var i=0;i<parent_project.Children.length;i++)
{
if(child_project.indexOf(parent_project.Children[i])<=-1)
child_project.push(parent_project.Children[i]);
}
for(var i=0;i<child_project.length;i++)
{ var temp = child_project[i];
child_project.splice(i,1);
get_child_recursively(temp);
}
}
else{
return;
}
if(child_project.length==0 || child_project.length==1){
return projects_array;
}
}
function projectDropDownChanged(dropdown,eventArgs){
projectName = eventArgs.value;
//loadTeamMembersDropDown();
}
function loadTeamMembersDropDown(){
var rallyDataSource = new rally.sdk.data.RallyDataSource("__WORKSPACE_OID__","__PROJECT_OID__","__PROJECT_SCOPING_UP__","__PROJECT_SCOPING_DOWN__");
var rallyqueryObject = {
key: "projects",
type: "project",
fetch: "TeamMembers,Name",
query: rally.sdk.util.Query('Name = "' + projectName + '"' ),
order: "Name desc"
};
rallyDataSource.findAll(rallyqueryObject,processTeamMemberResult);
}
function processTeamMemberResult(results){
var teamMember = results.projects;
}
rally.addOnLoad(onLoad);
</script>
</head>
<body class="teamApp">
<table>
<tr height="50px">
<td width="300px">
<div id="projectDropDown"></div>
</td>
</tr>
</table>
</body>
</html>
我尝试了各种调试方法,方法是在方法1中打印data
数组,从方法2打印data
数组,并比较存储的JSON格式,两者看起来相似。仍然,由于某种原因,方法1中的data
数组由下拉框加载,而当我尝试从方法2加载data
数组时,我什么也看不到。
任何建议都非常感谢!
答案 0 :(得分:0)
我建议使用最新的AppSDK 2rc1。有关它的文档here。 在下面的代码中,我构建了两个下拉列表。首先是project picker,然后根据项目选择填充user combobox。要粘贴到Rally自定义页面的完整HTML代码是in this repo。
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
var c = Ext.create('Ext.Container', {
items: [
{
xtype: 'rallyprojectpicker',
listeners:{
change: function(combobox){
if (!this.down('#u')) {
this._onProjectSelected(combobox.getSelectedRecord());
}
else{
Ext.getCmp('u').destroy();
this._onProjectSelected(combobox.getSelectedRecord());
}
},
scope: this
}
}
],
});
this.add(c);
},
_onProjectSelected:function(record){
var project = record.data['_ref'];
console.log('project', project);
var u = Ext.create('Rally.ui.combobox.UserComboBox',{
id: 'u',
project: project,
listeners:{
ready: function(combobox){
this._onUserSelected(combobox.getRecord());
},
select: function(combobox){
this._onUserSelected(combobox.getRecord());
},
scope: this
}
});
this.add(u);
},
_onUserSelected:function(record){
var user = record.data['_ref'];
console.log('user', user);
}
});
答案 1 :(得分:0)
由于Rally中工作区中的项目名称重复,因此返回给我的数组中有重复项。 <{1}}传递给下拉容器时不应包含重复项。