2014-07-01 52 views
0

我一直在试图查询拉力赛只是为了通过它的ObjectID来获得某个对象,但后来我在许多情况下最终需要它的父项。例如,对于任务,我需要与其关联的用户故事以及该故事的功能。它最终是相当多的回调(公平的警告,这是丑陋的) - 任何人都可以推荐一个更有效的解决方案?通过OID进行查询的功能非常好,但它太糟糕了,我需要的不仅仅是关于该OID的信息。 (注 - 解决方案必须使用WSAPI,而不是LBAPI)。拉力赛 - 更有效的方式来获得项目编号

Rally.data.WsapiModelFactory.getModel({ 
     type: 'Task', 
     context: { 
      workspace: Rally.util.Ref.getRelativeUri() 
     }, 
     success: function(taskModel) { 
      taskModel.load(oid, { 
       scope: this, 
       callback: function(taskRecord, op, success) { 
        if (taskRecord && taskRecord.data.WorkProduct && taskRecord.data.WorkProduct._type == "HierarchicalRequirement") { 


         // get User Story 
         Rally.data.WsapiModelFactory.getModel({ 
          type: 'User Story', 
          context: { 
           workspace: Rally.util.Ref.getRelativeUri() 
          }, 
          success: function(userStoryModel) { 
           userStoryModel.load(taskRecord.data.WorkProduct._ref, { 
            scope: this, 
            callback: function(storyRecord, op, success) { 

             if (storyRecord && storyRecord.data && storyRecord.data.Feature) { 

              // Get Feature 
              Rally.data.WsapiModelFactory.getModel({ 
               type: 'PortfolioItem/Feature', 
               context: { 
                workspace: Rally.util.Ref.getRelativeUri() 
               }, 
               success: function(featureModel) { 
                featureModel.load(storyRecord.data.Feature._ref, { 
                 scope: this, 
                 callback: function(featureRecord) { 
                  displayTask(oid, taskRecord, storyRecord, featureRecord); 
                 } 
                }); 
               } 
              }); 
             } 
            } 
           }); 
          } 
         }); 
        } 
       } 
      }); 
     } 
    }); 

回答

2

您可以直接在单个查询中提取工作产品父级及其关联的功能。试试这个:

Ext.create('Rally.data.WsapiDataStore', { 
     model : 'Task', 
     fetch : ['WorkProduct','Name','Feature'], 
     filters : [{ 
      property : 'ObjectID', 
      value : OID 
     }] 
    }).load({ 
     callback : function(records, operation, success) { 
      var task  = records[0]; 
      var userStory = task.get('WorkProduct'); 
      var feature = userStory.Feature; 
     } 
    }); 
+0

我曾试过一个查询就像这样开始,但没有得到任何结果。你的回答鼓励我再试一次 - 事实证明,我只需要指定上下文,然后这完美地工作。谢谢! –

+0

很高兴能帮到你! –

相关问题