我构建了一个自定义纸板mashup,用于显示所有用户故事,这些故事处于“已提交”的迭代状态,并且正在进行当前项目或任何子项目。这很好用。然后我添加了一个所有者下拉框(仅限团队成员),以过滤纸板上的故事。生成的查询值似乎格式正确,但未显示任何故事。我使用警报来复制查询字符串并将其粘贴到自定义网格中,该网格返回了预期的故事列表。
以下是我的代码。任何帮助表示赞赏。
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>
答案 0 :(得分: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;
....