2012-09-13 19 views
2

我对拉力赛开发非常陌生,所以我的问题可能听起来很愚蠢(但无法找到如何从拉力赛的帮助或从此前的帖子):)从拉力赛获取一个特定的标签,以便计算另一个字段的值

我已经从拉力赛自由形式的网格例子开始 - 我的目的是实现一个商业价值计算器:我用5位数字填充得分字段,其中每个数字都是1-5中的分数范围。 然后我计算一个商业价值作为计算的结果,其中每个数字是由预先设定的权重加权。 我可以按商业价值对我的故事进行排序,以帮助我优先处理我的积压工作:这是第一步,它很有效。

现在我想要做的是让我的自由形式网格可编辑:我将每个数字作为单独的列提取,但这些列仅显示。我怎样才能把它们变成可编辑的东西?我想要做的当然是根据每个自定义列中输入的值更新分数字段。

这里有一个例子: 我有分数“15254”的记录,这意味着商业价值标准1分1分商业价值准则2分5分等等... 在结束我的商业价值计算为“1 * 1 + 5 * 2 + 2 * 3 + 5 * 4 + 4 * 5 = 57”。 到目前为止,这是工作的部分。 现在,假设我发现第三个标准不应得分2但是3,我希望能够编辑相应列中的值并将我的分数字段更新为“15354”,并且我的业务价值显示为60而不是57.

这里是我当前的代码,我会非常感激,如果你能帮助我打开该网格到的东西可编辑:)

<!--Include SDK--> 
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0p2/sdk-debug.js"></script> 

<!--App code--> 
<script type="text/javascript"> 

    Rally.onReady(function() { 

     Ext.define('BVApp', { 
      extend: 'Rally.app.App', 
      componentCls: 'app', 

      launch: function() { 
      Ext.create('Rally.data.WsapiDataStore', { 
        model: 'UserStory', 
        autoLoad: true, 
        listeners: { 
         load: this._onDataLoaded, 
         scope: this 
        } 
       }); 
      }, 

      _onDataLoaded: function(store, data) { 
       var records = []; 
       var li_score; 
       var li_bv1, li_bv2, li_bv3, li_bv4, li_bv5, li_bvtotal; 
       var weights = new Array(1, 2, 3, 4, 5); 

       Ext.Array.each(data, function(record) { 
        //Let's fetch score and compute the business values... 
        li_score = record.get('Score'); 
        if (li_score) { 
         li_bv1 = li_score.toString().substring(0,1); 
         li_bv2 = li_score.toString().substring(1,2); 
         li_bv3 = li_score.toString().substring(2,3); 
         li_bv4 = li_score.toString().substring(3,4); 
         li_bv5 = li_score.toString().substring(4,5); 
         li_bvtotal = 
          li_bv1*weights[0] + 
          li_bv2*weights[1] + 
          li_bv3*weights[2] + 
          li_bv4*weights[3] + 
          li_bv5*weights[4]; 
        } 
        records.push({ 
         FormattedID: record.get('FormattedID'), 
         ref: record.get('_ref'), 
         Name: record.get('Name'), 
         Score: record.get('Score'), 
         Bv1: li_bv1, 
         Bv2: li_bv2, 
         Bv3: li_bv3, 
         Bv4: li_bv4, 
         Bv5: li_bv5, 
         BvTotal: li_bvtotal 
        }); 
       }); 

       this.add({ 
        xtype: 'rallygrid', 
        store: Ext.create('Rally.data.custom.Store', { 
         data: records, 
         pageSize: 5 
        }), 
        columnCfgs: [ 
         { 
          text: 'FormattedID', dataIndex: 'FormattedID' 
         }, 
         { 
          text: 'ref', dataIndex: 'ref' 
         }, 
         { 
          text: 'Name', dataIndex: 'Name', flex: 1 
         }, 
         { 
          text: 'Score', dataIndex: 'Score' 
         }, 
         { 
          text: 'BusVal 1', dataIndex: 'Bv1' 
         }, 
         { 
          text: 'BusVal 2', dataIndex: 'Bv2' 
         }, 
         { 
          text: 'BusVal 3', dataIndex: 'Bv3' 
         }, 
         { 
          text: 'BusVal 4', dataIndex: 'Bv4' 
         }, 
         { 
          text: 'BusVal 5', dataIndex: 'Bv5' 
         }, 
         { 
          text: 'BusVal Total', dataIndex: 'BvTotal' 
         } 
        ] 
       }); 
      } 
     }); 

     Rally.launchApp('BVApp', { 
      name: 'Business Values App' 
     }); 

       var exampleHtml = '<div id="example-intro"><h1>Business Values App</h1>' + 
       '<div>Own sample app for Business Values</div>' + 
           '</div>'; 

       // Default app viewport uses layout: 'fit', 
       // so we need to insert a container into the viewport 
       var viewport = Ext.ComponentQuery.query('viewport')[0]; 
       var appComponent = viewport.items.getAt(0); 
       var viewportContainerItems = [{ 
        html: exampleHtml, 
        border: 0 
       }]; 

       //hide advanced cardboard live previews in examples for now 

        viewportContainerItems.push({ 
         xtype: 'container', 
         items: [appComponent] 
        }); 


       viewport.remove(appComponent, false); 
       viewport.add({ 
        xtype: 'container', 
        layout: 'vbox', 
        items: viewportContainerItems 
       }); 
    }); 


</script> 

<!--App styles--> 
<style type="text/css"> 
    .app { 
     /* Add app styles here */ 
    } 
</style> 

+0

我已经取得了一些进展是:我已经取代我的网格上,我运用的Ext.grid.Panel行模式选择类型和Ext.grid.plugin.RowEditing插件。 我还为我的分数和名称列(现在)添加了一个编辑器:{xtype:'textfield'}属性,但它仅在显示器上修改数据,它不会将修改后的数据从我的自定义商店推送到WsapiDataStore ...我仍然不知道该怎么做......任何人有任何想法? – 4jas

+0

Rally.data.custom.Store不知道如何与Rally进行通信,因为它仅在内存中。你的编辑部分是正确的。您需要创建一个扩展用户故事模型的模型,以便它了解如何执行更新...... –

回答

1

像凯尔在他的评论中说的,你最好的选择是扩展用户故事模型,而不是使用内存存储。

扩展它,你可以使用Rally.data.ModelFactory来获取模型,然后做这样的事情:

Rally.data.ModelFactory.getModel({ 
    type: 'user story', 
    success: function(model){ 
     this.CustomModel = Ext.define('BVModel', { 
      extend: model, 
      fields: [ 
       {name: 'Bv1'} 
       ... 
      ] 
     }); 
    }, 
    scope: this 
}); 

然后使用convert配置上的得分字段设置的值你的计算字段。要获得在编辑时设置的分数,您可能还需要在每个计算字段上进行转换配置。

,然后告诉电网使用的,而不是商店自定义模式:

this.add({ 
    xtype: 'rallygrid', 
    model: this.CustomModel, 
    columnCfgs: [ 
     { 
      text: 'FormattedID', dataIndex: 'FormattedID' 
     }, 
     { 
      text: 'ref', dataIndex: 'ref' 
     }, 
     { 
      text: 'Name', dataIndex: 'Name', flex: 1 
     }, 
     { 
      text: 'Score', dataIndex: 'Score' 
     }, 
     { 
      text: 'BusVal 1', dataIndex: 'Bv1' 
     }, 
     { 
      text: 'BusVal 2', dataIndex: 'Bv2' 
     } 
    ] 
}); 
+0

谢谢,这真的看起来像一个非常有趣的方向。我已经开始重写我的代码,但现在我在SDK中发生了一个错误:我为此创建了一个新帖子:http://stackoverflow.com/questions/12555812/extending-userstory-model-with-a-custom-场失败 - 与 - 编译 - 功能 - 不是-F – 4jas

相关问题