0

继续我的应用程序,其目的是能够编辑聚合字段并将计算结果存储在另一个字段中该聚合的各个组件上......

我现在可以使用 UserStory 模型的扩展正确检索我的字段,但我仍然无法保存我的更改。我试图检查 Ext.grid.plugin.RowEditing 的编辑事件中做了什么,我注意到当我到达它时, e.store.data.items[rowIdx].data 包含我所有的预期值,它的脏和编辑标志是错误的,但 e.store.data.items[rowIdx].raw 没有反映这一点(它包含拉力赛的原始值,未修改) - 即使我尝试编辑原始值,它也不起作用:

plugins: [
    Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1,
        listeners: {
            'edit': function (editor, e) {
                e.store.data.items[e.rowIdx].raw.BusinessValues =
                    e.store.data.items[e.rowIdx].data.BusinessValues;

                e.store.commitChanges();
            }
        }
    })
]

整个代码如下,但我想知道是否应该在模型级别添加一个监听器?

Rally.onReady(function() {
    Ext.define('BVApp', {
        extend: 'Rally.app.App',
        componentCls: 'app',
        launch: function() {
            Rally.data.ModelFactory.getModel({
            type: 'UserStory',
            success: function(model) {
                var weights = new Array(5, 3, 1, 3, 4, 4, 2, 2);
                var BvTitles = new Array("Customers Impact", "Critical Path", "Usability", "Functionality", "Security", "Performance", "Integration", "Integrity", "Business Value");
                //var BvTitlesFrench = new Array("Parc Client", "Chemin Critique", "Ergonomie", "Fonctionnalité", "Sécurité", "Performance", "Intégration", "Intégrité", "Valeur Métier");

                // Thanks to question http://stackoverflow.com/questions/12517383/sdk2-links-in-rally-grids-and-column-width I can now remove flex from FormattedID column...
                var fixedIDwithLink = Rally.ui.grid.FieldColumnFactory.getColumnConfigFromField( model.getField( 'FormattedID' ) );
                fixedIDwithLink.flex = false;
                fixedIDwithLink.width = 70;

                function getOneBV( record, pos, newValue ) {
                    var ls_BvFieldStart, ls_BvFieldEnd, ls_BvFromBvField;
                    if ( pos < 1 ) return newValue; // ERROR in fact...
                    if ( pos > 8 ) return newValue;
                    ls_BvFieldStart = record.data.BusinessValues.substring( 0, pos-1 );
                    ls_BvFromBvField = record.data.BusinessValues.substring( pos-1, pos );
                    ls_BvFieldEnd = record.data.BusinessValues.substring( pos, 8 );
                    if ( newValue ) {
                        ls_BvFromBvField = newValue;
                        record.data.BusinessValues = ls_BvFieldStart + ls_BvFromBvField + ls_BvFieldEnd;
                    }
                    return ls_BvFromBvField;
                }
                function getbv( as_bvHolder ) {
                    var li_bv1, li_bv2, li_bv3, li_bv4, li_bv5, li_bv6, li_bv7, li_bv8, li_bvtotal;
                    li_bv1 = as_bvHolder.substring( 0,1 );
                    li_bv2 = as_bvHolder.substring( 1,2 );
                    li_bv3 = as_bvHolder.substring( 2,3 );
                    li_bv4 = as_bvHolder.substring( 3,4 );
                    li_bv5 = as_bvHolder.substring( 4,5 );
                    li_bv6 = as_bvHolder.substring( 5,6 );
                    li_bv7 = as_bvHolder.substring( 7,8 );
                    li_bv8 = as_bvHolder.substring( 8,9 );
                    li_bvtotal =
                        li_bv1*weights[0] +
                        li_bv2*weights[1] +
                        li_bv3*weights[2] +
                        li_bv4*weights[3] +
                        li_bv5*weights[4] +
                        li_bv6*weights[5] +
                        li_bv7*weights[6] +
                        li_bv8*weights[7];
                    return li_bvtotal;
                }

                this.grid = this.add({
                    xtype: 'rallygrid',
                    model: Ext.define('BVModel', {
                        extend: model,
                        alias : 'BVModel',
                        fields: [
                            {name: 'Bv1', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 1, v ); }
                            },
                            {name: 'Bv2', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 2, v ); }
                            },
                            {name: 'Bv3', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 3, v ); }
                            },
                            {name: 'Bv4', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 4, v ); }
                            },
                            {name: 'Bv5', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 5, v ); }
                            },
                            {name: 'Bv6', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 6, v ); }
                            },
                            {name: 'Bv7', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 7, v ); }
                            },
                            {name: 'Bv8', type: 'string', persist: false,
                                convert: function(v, record){ return getOneBV( record, 8, v ); }
                            },
                            {name: 'BvTotal', type: 'string', persist: false,
                                convert: function( v, record ) {
                                    var ls_scoreInfo = '';
                                    if ( record.data.BusinessValues ) {
                                        ls_scoreInfo = getbv( record.data.BusinessValues ) + ' ';
                                    }
                                    if ( record.data.Score ) {
                                        ls_scoreInfo += '(previous: ' + record.data.Score + ')';
                                    }
                                    return ls_scoreInfo;
                                }
                            }
                        ]
                    }),
                        storeConfig: {
                            pageSize: 30, autoLoad: true, filters: [
                                {
                                    property: 'ScheduleState',
                                    operator: '=',
                                    value: 'Backlog'
                                }
                                //,{ property: 'FormattedID', value: 'US85792' } // US85792, US84529, US81387, US77032
                            ],
                            context: this.getContext().getDataContext()
                        },
                    columnCfgs: [
                        fixedIDwithLink, // might want to add a select listener later to display details in a child pane ?
                        'Name',
                        'BusinessValues',
                        'AffectedCustomers',
                        {
                            text: BvTitles[0], dataIndex: 'Bv1', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[1], dataIndex: 'Bv2', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[2], dataIndex: 'Bv3', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[3], dataIndex: 'Bv4', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[4], dataIndex: 'Bv5', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[5], dataIndex: 'Bv6', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[6], dataIndex: 'Bv7', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[7], dataIndex: 'Bv8', editor: { xtype: 'textfield' }, width: 70
                        },
                        {
                            text: BvTitles[8], dataIndex: 'BvTotal', editor: { xtype: 'textfield' }
                        }
                    ],
                    selType: 'rowmodel',
                    plugins: [
                        Ext.create('Ext.grid.plugin.RowEditing', {
                            clicksToEdit: 1,
                            listeners: {
                                'edit': function (editor, e) {
                                    e.store.data.items[e.rowIdx].raw.BusinessValues = e.store.data.items[e.rowIdx].data.BusinessValues;
                                    e.store.commitChanges();
                                }
                            }
                        })
                    ]
                });

                }, // end of getModel success
                scope: this
            });
        }
    });

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

});
4

1 回答 1

0

我的建议是使用记录对象的 get & set 函数来检索和更改数据,而不是挖掘“数据”或“原始”字段。这样,Ext 库可以更好地管理更改以正确更新存储/记录。

因此,当您想要获取“BusinessValues”字段的值时,请使用record.get('BusinessValues'). 同样,尝试record.set('BusinessValues', newValue)在 getOneBV 函数中设置新值。在执行此操作时,您可能能够注释掉您添加的 RowEditing 插件。

于 2012-09-24T16:34:40.250 回答