1

我构建了一个自定义的纸板混搭来显示所有处于“已提交”迭代中并属于当前项目或任何子项目的用户故事。这很有效。然后我添加了一个所有者下拉框(仅限团队成员),以过滤纸板上的故事。结果查询值的格式似乎很好,但没有显示任何故事。我使用警报复制查询字符串并将其粘贴到自定义网格中,该网格返回预期的故事列表。

下面是我的代码。任何帮助表示赞赏。

        var rallyDataSource;
        var cardboard;
        var ownerDropdown;

        function refreshCardboard() {

            var cardboardConfig = {
                types: ["Defect", "HierarchicalRequirement"],
                attribute: "ScheduleState",
                fetch: "Name,FormattedID,Owner,ObjectID"
            };

            var query = rally.sdk.util.Query.and(['Iteration.Name != ""', 'Iteration.State = "Committed"']);

            if (ownerDropdown) {
                var ownerQuery = ownerDropdown.getValue();
                if (ownerQuery != 'ALL') {
                    query = '(' + query + ' AND Owner.Name = "' + ownerQuery + '")';
                }
            }

            cardboardConfig.query = query;
            if (!cardboard) {
                cardboard = new rally.sdk.ui.CardBoard(cardboardConfig, rallyDataSource);
                cardboard.display("cardboardDiv");
            } else {
                cardboard.refresh(cardboardConfig);
            }
        }

        function buildOwnerDropdown() {

            var teamMembersQuery = {
                key: "teamMembers",
                type: "User",
                fetch: "UserName,DisplayName",
                query: '(TeamMemberships = /project/__PROJECT_OID__)'
            };

            rallyDataSource.findAll(teamMembersQuery, function (results) {

                var ownerItems = [{ label: "-- ALL --", value: "ALL"}];
                rally.forEach(results.teamMembers, function (teamMember) {
                    ownerItems.push({ label: teamMember.DisplayName, value: teamMember.UserName });
                });

                ownerItems.sort();

                var ownerDropdownConfig = {
                    showLabel: true,
                    label: "Owner:",
                    items: ownerItems
                };

                ownerDropdown = new rally.sdk.ui.basic.Dropdown(ownerDropdownConfig);
                ownerDropdown.display("ownerDropdownDiv");
            });
        }

        function onLoad() {

            rallyDataSource = new rally.sdk.data.RallyDataSource(
                '__WORKSPACE_OID__',
                '__PROJECT_OID__',
                '__PROJECT_SCOPING_UP__',
                '__PROJECT_SCOPING_DOWN__');

            buildOwnerDropdown();

            refreshCardboard();
        }

        rally.addOnLoad(onLoad);

    </script>

</head>
<body>
    <div id="ownerDropdownDiv"></div>
    <input id="refreshButton" type="button" value="Filter" onclick="refreshCardboard()"/>
    <div id="cardboardDiv"></div>
</body>
4

1 回答 1

0

你真的很接近目标 - 问题出在:

        var query = rally.sdk.util.Query.and(['Iteration.Name != ""', 'Iteration.State = "Committed"']);

        if (ownerDropdown) {
            var ownerQuery = ownerDropdown.getValue();
            if (ownerQuery != 'ALL') {
                query = '(' + query + ' AND Owner.Name = "' + ownerQuery + '")';
            }
        }

在添加另一个 AND 条件时,Rally 的查询语法需要另一组嵌套的括号。因此,当您连接第三个条件时,您将得到一个如下所示的查询子句:

((Iteration.Name != "") AND (Iteration.State = "Committed")) AND (Owner.Name = "user@company.com")

当它需要看起来像这样时:

(((Iteration.Name != "") AND (Iteration.State = "Committed")) AND (Owner.Name = "user@company.com"))

我稍微修改了您的 refreshCardboard() 函数的查询逻辑,如下所示,您的代码现在似乎对我有用。

    ....        
    var queryArray = new Array('Iteration.Name != ""', 'Iteration.State = "Committed"');                                       
    var query;

    var selectedOwner = ownerDropdown.getValue();

    if (ownerDropdown) {
       if (selectedOwner != 'ALL') {
          var ownerClause = 'Owner.Name = "' + selectedOwner + '"';
          queryArray.push(ownerClause);
       }
    }

    query = rally.sdk.util.Query.and(queryArray);

    cardboardConfig.query = query;
    ....
于 2013-02-06T00:48:03.087 回答