拉力赛 - 通过ID获取项目的更有效方式

时间:2014-07-01 14:54:26

标签: rally appsdk2

我一直在尝试查询Rally只是为了通过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);
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        });
                    }
                }
            });
        }
    });

1 个答案:

答案 0 :(得分: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;
        }
    });