Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Rally SDK 2中,如何更新数组字段,比如变更集的工件?_Javascript_Rally - Fatal编程技术网

Javascript 在Rally SDK 2中,如何更新数组字段,比如变更集的工件?

Javascript 在Rally SDK 2中,如何更新数组字段,比如变更集的工件?,javascript,rally,Javascript,Rally,因此,我为变更集创建了一个模型,获取一个包含2个工件的变更集,并获取工件字段。当我把它记录下来时,我得到了两个项目。我有另一个项目(任务)要推到这个领域。当我控制台记录工件数组时,我得到三个项目 但是,当我直接或使用set()设置字段时,我会记录变更集,它仍然认为只有两个工件。我可能做错了什么 Rally.data.ModelFactory.getModel({ type: 'Changeset', success: function(model) {

因此,我为变更集创建了一个模型,获取一个包含2个工件的变更集,并获取工件字段。当我把它记录下来时,我得到了两个项目。我有另一个项目(任务)要推到这个领域。当我控制台记录工件数组时,我得到三个项目

但是,当我直接或使用set()设置字段时,我会记录变更集,它仍然认为只有两个工件。我可能做错了什么

Rally.data.ModelFactory.getModel({
      type: 'Changeset',
      success: function(model) {
             model.load( '1234', {
                  fetch: [ 'Artifacts' ],
                  callback: function(result, operation) {
                            if ( operation.wasSuccessful() ){
                                var artifacts = result.get('Artifacts');
                                if ( ! artifacts ) {
                                    artifacts = [];
                                }
                                artifacts.push( item );
                                console.log( artifacts );

                                result.data.Artifacts = artifacts;
                                //result.set('Artifacts', artifacts);

                                console.log( result );
                                result.save( {
                                    callback: function( result, operation ) {
                                    console.log( "After saving: ", operation );
                                    }
                                    } );
                            }
                   }
             })
      }
});

看起来您需要创建一个新的artifacts数组,因为在使用同一数组进行设置时,它不会将记录标记为dirty(可能是Rally代码或Ext代码中的错误)。 此外,还需要传递工件的数据对象(在下面的示例中为newUserStory.data)

我调整了您的代码,制作了一个创建存储库、变更集和用户故事的示例;然后将该用户故事附加到变更集的工件集合。 如果完整地运行此代码,则需要将每个对象创建与更新代码分开运行,因为它们是异步的,但相互依赖。另一个选项是在每个save()调用中进行回调

创建必要的域对象:

   var newRepo, newChangeset, newUserStory;

Rally.data.ModelFactory.getModel({
      type: 'SCMRepository',
      success: function(model) {
          newRepo = new model({
            Name: 'Repo1',
            SCMType: 'SCM Type 1'   
          });
          newRepo.save();
      }
});

Rally.data.ModelFactory.getModel({
      type: 'Changeset',
      success: function(model) {
          newChangeset = new model({
            CommitTimestamp: '2012-06-20 01:00:00',
            Revision: 'revision1',
            SCMRepository: newRepo.data._ref
          });
          newChangeset.save();
      }
});


Rally.data.ModelFactory.getModel({
      type: 'UserStory',
      success: function(model) {
          newUserStory = new model({
            Name: 'Test story ' + new Date()
          });
          newUserStory.save();
      }
});
现在更新变更集:

Rally.data.ModelFactory.getModel({
      type: 'Changeset',
      success: function(model) {
          model.load( newChangeset.data.ObjectID, {
                  fetch: [ 'Artifacts' ],
                  callback: function(result, operation) {
                      if ( operation.wasSuccessful() ){         
                            var artifacts = result.get('Artifacts'),
                                artifactsCopy = Ext4.Array.clone(artifacts);

                            artifactsCopy.push(newUserStory.data);
                            result.set('Artifacts', artifactsCopy);

                            result.save( {
                                callback: function( result, operation ) {
                                    if (operation.wasSuccessful()) {
                                        var artifactInUpdate = Ext4.Array.filter(result.data.Artifacts, function(artifact) {
                                            return artifact._ref === newUserStory.data._ref;
                                        });

                                        console.log('Userstory added to changeset:', artifactInUpdate.length > 0);
                                    } else { 
                                        console.log('update not successful');
                                    }
                                }
                            });
                        }
                  }
           });
      }
});

周末发布的SaaS解决了这个问题。现在可以发送一个工件数组,该数组将替换原始列表,就像WSAPI中的其他数组一样。

谢谢。不过,现在我无法从变更集中删除故事。