ExtJS - 获取刚刚保存的记录的ID

时间:2021-12-15 18:48:44

I need to save some data and return the ID that is created in the SQL 2005 database. I need the ID to pass to another object before saving that so I can associate them correctly.

我需要保存一些数据并返回在SQL 2005数据库中创建的ID。在保存之前我需要将ID传递给另一个对象,以便我可以正确地关联它们。

What is the best way to accomplish this with Ext? Is there anything built into the Framework that makes this simple?

使用Ext实现此目的的最佳方法是什么?框架内置了什么使这个变得简单?

Thanks.

谢谢。

                function AddPromotionType() {
                var currentDate = new Date();
                var newTypeJsonObject = {
                    promotionTypeId: '0',
                    promotionType: Ext.getCmp('txtPromoType').getValue(),
                    updatedBy: userid, 
                    updateDate: currentDate
                }

                // serialize our service object
                var newLevelJsonData = Ext.encode(newTypeJsonObject);

                // call the web service and pass over our service object
                Ext.lib.Ajax.defaultPostHeader = 'application/json';
                Ext.Ajax.request({
                    url: 'Service/AddPromoType',
                    method: 'POST',
                    params: newLevelJsonData,
                    success: function(response, options) {
                        AddTypeWindow.destroy();
                        AddTypeWindow.hide();

                        // refresh dropdown to reflect new data

                        Ext.getCmp('newPromoType').getStore().reload();                        
                    },
                    // if data fails to save, show message
                    failure: function(response, options) {
                        Ext.MessageBox.alert('Error saving new promotion type', response.responseText);
                    }
                });
            }

1 个解决方案

#1


1  

Assuming your server is passing back the updated data with the new id the response param of your success callback should contain it. When using the facilities built into Stores that automate Ajax calls (e.g., Ext Direct, REST API support, etc.) the id gets automatically updated on the appropriate Record for you and you can handle the store's add event to inspect the Record. However, since you're doing a manual Ajax call it's up to you to inspect your response if you need the id immediately.

假设您的服务器使用新id传回更新的数据,则成功回调的响应参数应包含它。当使用Stores内置的自动化Ajax调用的工具(例如,Ext Direct,REST API支持等)时,id会自动在适当的Record上更新,您可以处理商店的add事件来检查Record。但是,由于您正在进行手动Ajax调用,因此如果您需要立即使用id,则由您来检查您的响应。

#1


1  

Assuming your server is passing back the updated data with the new id the response param of your success callback should contain it. When using the facilities built into Stores that automate Ajax calls (e.g., Ext Direct, REST API support, etc.) the id gets automatically updated on the appropriate Record for you and you can handle the store's add event to inspect the Record. However, since you're doing a manual Ajax call it's up to you to inspect your response if you need the id immediately.

假设您的服务器使用新id传回更新的数据,则成功回调的响应参数应包含它。当使用Stores内置的自动化Ajax调用的工具(例如,Ext Direct,REST API支持等)时,id会自动在适当的Record上更新,您可以处理商店的add事件来检查Record。但是,由于您正在进行手动Ajax调用,因此如果您需要立即使用id,则由您来检查您的响应。