2

在 Rally SDK 2 中,如何更新哈希字段,例如变更集的作者字段?我阅读了如何更新 Message 字段,但我不知道如何更新 Author["DisplayName"] 哈希。

var new_message = settings.message;
Rally.data.ModelFactory.getModel({
  type: 'Changeset',
  success: function(model) {
         model.load( '1234', {
              fetch: [ 'Artifacts' ],
              callback: function(result, operation) {
                        if ( operation.wasSuccessful() ){
                            var message = new_message;
                            record.set( 'Message', message);
                            record.save( {
                                callback: function( resultset, operation ) {
                                    console.log( "After saving:", resultset );
                                    if ( operation.wasSuccessful() ) {
                                        var that = tree.ownerCt.ownerCt.ownerCt.ownerCt;
                                        that._getChangesets();
                                    }
                                }
                            } ); 
                        }
               }
         })
  }

});

4

1 回答 1

0

Changeset 上的 Author 属性是 User 类型。与 Rally 的 WSAPI 上的任何其他对象关联一样,您只需将此属性设置为您要链接的对象的引用。您的设置方式与当前在上述代码段中设置 Message 的方式相同。(假设作者在变更集创建后是可写的)。

record.set('Author', '/user/123456');

您还可以通过在回调中指定范围并在应用程序定义中使用成员函数来避免代码的深度嵌套结构:

_loadChangesetModel: function() {
    //If you already have a changeset record you can get the model
    //via record.self.  Otherwise, load it fresh.
    Rally.data.ModelFactory.getModel({
        type: 'Changeset',
        success: this._onChangesetModelLoaded,
        scope: this
    });
},

_onChangesetModelLoaded: function(model) {
    model.load( '1234', {
        fetch: [ 'Artifacts' ],
        callback: this._onChangesetLoaded,
        scope: this
    });
},

_onChangesetLoaded: function(record, operation) {
    if ( operation.wasSuccessful() ){
        var message = settings.message;
        record.set( 'Message', message);
        record.save( {
            callback: this._onChangesetSaved,
            scope: this
        } ); 
    }
},

_onChangesetSaved: function( resultset, operation ) {
    console.log( "After saving:", resultset );
    if ( operation.wasSuccessful() ) {
        //You shouldn't need to do this now that the scope is correct.
        //I'm guessing 'that' was referring to the app itself?
        //var that = tree.ownerCt.ownerCt.ownerCt.ownerCt;
        this._getChangesets();
    }
},

_getChangesets: function() {
    //refresh
}
于 2013-03-10T16:44:02.410 回答