1

我正在尝试使用 Rally sdk 编写一些 js 来获取与项目关联的团队成员列表。我的下拉框将包含我当前的项目及其子项目的列表。选择后,它将提供所选项目的团队成员列表。

到目前为止,我尝试了两种方式:

  1. 一种没有所有子项目的相当简单的方法,在这里我只获得当前项目的第一级子项目(而不是递归地获得所有子项目)。

  2. 递归获取当前项目的所有子项目。

到目前为止,我只能完成(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构造函数。但由于某种原因,当我在 Rally 中运行它时,我没有得到任何输出。我什至没有在 Rally 中显示下拉框,只是一个空白应用程序。

这是我的代码:

      <!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>

我尝试了各种调试方法,方法是打印data方法 1 中的data数组和方法 2 中的数组,并比较了存储的 JSON 格式,两者看起来都很相似。尽管如此,由于某种原因,data方法 1 中的数组是由下拉框加载的,而当我尝试data从方法 2 中加载数组时,我什么也看不到。

任何建议都非常感谢!

4

2 回答 2

0

我建议使用最新的 AppSDK 2rc1。它的文档可在此处获得。在下面的代码中,我构建了两个下拉列表。首先,一个项目选择器,然后,根据项目选择,填充一个用户组合框。粘贴到 Rally 自定义页面的完整 html 代码在这个 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);
    }

});

于 2013-10-23T21:48:56.000 回答
0

由于我在 Rally 中的工作区中有重复的项目名称,因此返回给我的数组中有重复项。key传递给下拉容器时不应包含重复项。

于 2013-10-24T20:08:45.507 回答