显示后更改拉力赛基本下拉菜单

时间:2012-02-08 00:11:06

标签: drop-down-menu rally

我在Rally App中有一个rally.sdk.ui.basic.Dropdown菜单,我想根据用户输入更改。所以我将在下拉菜单上调用display(),然后我想更改该菜单的内容。

有人这样做过吗?当我尝试时,它会崩溃。我也尝试在下拉菜单上调用destroy(),然后在我分配的新菜单上调用display(),但是在崩溃的dojo错误中也会崩溃。

有关如何动态更改下拉菜单的任何建议吗?

我在下面包含了一个非常简单的示例,试图销毁并重新显示菜单:

<html>
  <head>
    <title>Incoming Defects by Severity</title>
    <meta http-equiv="X-UA-Compatible" content="IE=7" >
    <meta name="Name"    content="Defects by Severity" />

    <script type="text/javascript" src="https://rally1.rallydev.com/apps/1.29/sdk.js"></script>

    <script type="text/javascript">
        function DefectChart() {
            this.display = function() {
                var defectVersionDropdown;
                var count = 1;

                function makeDefectChart(results){
                    initDefectVersionDropdown();
                };

                function renderPage() {
                    var queryConfig = [];
                    var startDate   = '2011-06-06';
                    var endDate     = '2012-02-02';
                    var queryArray  = ['CreatedDate >= "' + startDate + '"', 'CreatedDate <= "' + endDate + '"'];
                    var versionFilter       = defectVersionDropdown ? defectVersionDropdown.getDisplayedValue() : 'ALL';
                        if (versionFilter != 'ALL') {
                            queryArray.push('FoundInBuild contains "' + versionFilter + '"');
                        }   
// console.log(queryArray);
                    queryConfig.push({
                        type : 'Defects',
                        key  : 'defects',
                        query:  rally.sdk.util.Query.and(queryArray),
                        fetch: 'Severity,State,LastUpdateDate,CreationDate,OpenedDate,AcceptedDate,LastUpdateDate,ClosedDate,Environment,FoundInBuild'
                    });

                    rallyDataSource.findAll(queryConfig, makeDefectChart);
                }

                function defectVersionChange(sender, eventArgs) {
                    var version = eventArgs.value;

                    renderPage();
                }

                function initDefectVersionDropdown() {
                    if (defectVersionDropdown != null) {
                        defectVersionDropdown.destroy();
                        defectVersionDropdown = null;
                    }

                    if (defectVersionDropdown == null) {
                  console.log('initDefectVersionDropdown'); 
                        count++;
                        var menuItems   = [{label: "ALL", value: "ALL"}];
                            for (var i=0; i < count; i++) {
                                menuItems.push({label: count, value: count});
                            }
                        var config  = {
                                label:  "Found In Version:",
                                items:  menuItems
                             };

                        defectVersionDropdown   = new rally.sdk.ui.basic.Dropdown(config);

                        defectVersionDropdown.addEventListener("onChange", defectVersionChange);
                        defectVersionDropdown.display("defectVersionDiv");
                    }
                }

                var workspaceOid    = '__WORKSPACE_OID__';  if (workspaceOid.toString().match(/__/))    { workspaceOid  = XXX; }
                var projectOid      = '__PROJECT_OID__';    if (projectOid.toString().match(/__/))      { projectOid    = XXX; }

                rallyDataSource = new rally.sdk.data.RallyDataSource(   workspaceOid,
                                                                        projectOid,
                                                                        '__PROJECT_SCOPING_UP__',
                                                                        '__PROJECT_SCOPING_DOWN__');
                initDefectVersionDropdown();
                renderPage();
            }
        }

        function getDataAndShow() {
            var defectChart = new DefectChart();

            defectChart.display();
        }

        function loadRally() {
            rally.addOnLoad(getDataAndShow);
        }

        loadRally();
    </script>
  </head>
  <body>
    <div id="defectVersionDiv"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

销毁旧的创建并显示新的是正确的方法。这是使用App SDK开发应用程序时的常见模式。如果您提供了一个与dojo错误一起剪切的代码,那么社区可能会提供更好的帮助。