1

I have some code that is pulling a Release model back and displaying in a grid, this is working fine, but I cannot work out how to inspect what is in the returned model.

What I would like is to get the contents of the model in some kind of object that I can reorganise or drill into as I see fit (in this case the release model).

If I add a component and just dump the model into the html it is not returning the contents as I would expect.

Rally.data.ModelFactory.getModel({
        type: 'Release',
        success: function(model) {
                this.add({
                    xtype: 'component',
                    html: model
                });

                this.grid = this.add({
                xtype: 'rallygrid',
                model: model,
                columnCfgs: [
                    'FormattedID',
                    'Name',
                    'RevisionHistory'                    ],
                storeConfig: {
                    filters: queryFilters
                }
            });
        },
        scope: this
    });                 

If I dig into the ExtJS docs it seems I should be able to do something like getData() on the model to return the contents but this is not working.

Inspection in the debugger tells me I have a "Rally.domain.v2.0.project.10098485624.Release" object but I can't see how to simply access the list of items in the object. Obviously there is a way because passing this model to a grid component will display it quite happily. The debugger for this object shows me a number of further functions to call but I have no idea which one or how to use it

...
getArtifactMappings: function () {
getCollectionFields: function () {
getCustomFields: function () {
getField: function (fieldName) {
getFields: function () {
getFieldsByName: function (fieldNames) {
getName: function () {
getNonCollectionFields: function () {
getPermissionLevels: function (permission) {
getProxy: function () {
etc...

The Rally docs indicate I should be able to call getData() on a model https://help.rallydev.com/apps/2.0rc2/doc/#!/api/Rally.data.Model but it looks like the ModelFactory.getModel() is not returning a type that has a getData() method

4

1 回答 1

1

模型是一个类,记录是该类的一个实例。

getData()将记录在案。有一些静态方法可以在实际模型上工作,但getData()不是其中之一。

这是下面代码的一个片段:

 _onDataLoaded: function(store, data){
      _.each(data, function(record){
         var r = record.getData();
         console.log('release', r);

此代码构建了一个按项目和 ReleaseStartDate 过滤的发布网格。我注意到在您的代码中,您希望通过实际修改 dom 来显示模型信息,也许是出于调试目的。我更喜欢使用 console.log,但在下面的示例中,我两者都使用了。我使用带有页脚的边框布局,并将页脚中容器的 html 属性设置为JSON.stringify(r)

  Ext.define('CustomApp', {
     extend: 'Rally.app.App',
     componentCls: 'app',
     layout:'border',
               defaults: {
                  collapsible: true,
                  split: true,
                  bodyStyle: 'padding:15px',
               },
                  items: [{
                      title: 'data',
                      region:'south',
                      itemId: 'd',
                      margins: '5 0 0 0',
                      cmargins: '5 5 0 0'

                  },{
                      title: 'Releases',
                      itemId: 'r',
                      collapsible: false,
                      region:'center',
                      margins: '5 0 0 0'
                  }] ,
      launch: function() {
        var context =  this.getContext();
        var projectId = context.getProject().ObjectID;
        var millisecondsInDay = 86400000;            
                    var currentDate = new Date();
                    var startDate = new Date(currentDate - millisecondsInDay*90); //in the last 90 days
                    var startDateUTC = startDate.toISOString();
         Ext.create('Rally.data.WsapiDataStore', {
            model: 'Release',
            fetch: ['Name','ReleaseStartDate','ReleaseDate', 'State'],
            filters: [
                        {
                        property: 'ReleaseStartDate',
                        operator: '>',
                        value: startDateUTC
                        },
                        {
                        property: 'Project',
                        operator: '=',
                        value: '/project/'+ projectId
                        }
                    ],
            autoLoad: true,
            listeners: {
                load: this._onDataLoaded,
                scope: this
            }
        });
    },


     _onDataLoaded: function(store, data){
     var text = '';
      _.each(data, function(record){
         var r = record.getData();
         console.log('release', r);
         text = text + JSON.stringify(r);
      });
      console.log('text', text);
         this.down('#d').add({
            xtype:'container',
            html: text
            });
         if (!this.down('#g')) {
            this.down('#r').add({
            xtype: 'rallygrid',
            store: store,
            itemId: 'g',
            columnCfgs: [
                {
                   text: 'Name', dataIndex: 'Name'
                },
                {
                   text: 'State', dataIndex: 'State'
                },
                {
                    text: 'Start Date', dataIndex: 'ReleaseStartDate', flex:1
                },
                {
                    text: 'Release Date', dataIndex: 'ReleaseDate',flex:1
                }
            ]

         }); 
         }
         else{
            (this.down('#g')).reconfigure(store);
         }

      }
 });

在此处输入图像描述

于 2014-01-30T19:58:12.083 回答