在Rally SDK 2中,如何更新哈希字段?

时间:2013-03-09 19:12:11

标签: rally

在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();
                                    }
                                }
                            } ); 
                        }
               }
         })
  }

});

1 个答案:

答案 0 :(得分:0)

Changeset上的Author属性属于User类型。与Rally的WSAPI上的任何其他对象关联一样,您只需将此属性设置为您要链接的对象的ref。您设置此方法的方式与您在上面的代码段中设置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
}