2013-02-28 46 views
1

我試圖根據選定的迭代進行查詢,並根據該迭代的故事顯示一些結果。拉力賽JavaScript沒有顯示任何內容,有查詢問題

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
    <meta name="Name" content="SubField Query" /> 
    <title>SubField Query Example</title> 
    <script src="/apps/1.26/sdk.js"></script> 
    <script type="text/javascript"> 
    function onLoad() { 
    rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__', 
           '__PROJECT_OID__', 
           '__PROJECT_SCOPING_UP__', 
           '__PROJECT_SCOPING_DOWN__'); 

    var iterConfig = {}; 
     iterDropdown = new rally.sdk.ui.IterationDropdown(iterConfig, rallyDataSource); 
     iterDropdown.display(document.getElementById("test"), onSelected); 
     rallyDataSource.findAll(queryConfig, showStories); 



} 

function showStories(results) { 
     var info = document.getElementById("info"); 
     info.innerHTML = "<b>Iteration Story Information</b><br>"; 
     var story; 
     for (var i = 0; i < results.stories.length; i++){ 
      story = results.stories[i]; 
      info.innerHTML += story.Name + ' - ' + story.Owner + ' - ' + story.Project + ' - ' + story.State + ' - ' + story.PlanEst + '<br>'; 
     } 
    }; 


function onSelected() { 
    var queryConfig = { 
    type: 'hierarchicalrequirement', 
    key: 'stories' 
    query: '(Iteration.Name =' + iterDropdown.getSelectedName() + ')' 
    fetch: 'Name, Owner, Project, State, PlanEst' 
    } 
    } 
    rally.addOnLoad(onLoad); 
</script> 
</head> 
<body> 
<h1>Test Report Page</h1> 
<div id = "test"></div> 
<div id = "info"></div> 
</body> 
</html> 

我對理解程序的流程有些困難。我看到它的方式,onLoad運行,並且在onLoad中調用onSelected函數來創建查詢,然後在findAll命令中使用該查詢來運行所述查詢。我曾嘗試過在各地移動showStories,看看是否改變了結果,但它什麼也沒做。請指教。

回答

0

JavaScript和回調的異步性質起初可能有點嚇人。你真的很親密。這裏是一些固定的代碼:

function onLoad() { 
    //code snipped above 
    //display the iteration dropdown and call onSelected when it's ready 
    iterDropdown.display(document.getElementById("test"), onSelected); 
} 

function onSelected() { 
    var queryConfig = { 
     type: 'hierarchicalrequirement', 
     key: 'stories', 
     query: '(Iteration.Name = "' + iterDropdown.getSelectedName() + '")', //include quotes around name 
     fetch: 'Name,Owner,Project,State,PlanEst' //no spaces in fetch 
    }; 

    //call rallyDataSource.findAll here, and showStories will be called with the data 
    rallyDataSource.findAll(queryConfig, showStories); 
} 

function showStories(results) { 
    //show stories here 
} 

//program execution starts here 
rally.addOnLoad(onLoad); 

所以基本的流程是onLoad,onSelected,showStories。

+0

也許你可能知道。我在哪裏可以找到所有查詢字段的名稱?我花了幾個小時才發現Task Est的可查詢名稱是TaskEstimateTotal。我能找到一箇中心位置嗎? 我想顯示所有者,但我不斷收到Object對象。我應該查詢什麼? – thisisnotabus 2013-03-01 15:28:37

+0

https://rally1.rallydev.com/slm/doc/webservice/將列出所有類型及其字段。所有者是用戶對象,因此您必須遍歷它才能獲取名稱。 – 2013-03-01 17:21:02