开发者

Ext.Direct: matching return values to calls

I am making a sequence of Ajax calls using the Ext.Direct module. I want to save some data when I make each call, and then match each return value with the correct call.

In the server call, Ext provide a tid property (presumable "transaction identifier") in the JSON packet which it uses match return values to calls. Problem is, there doesn't seem to be any documented way for my client-side Javascript to 开发者_开发知识库capture the tid of the outgoing call.

The following method works, but it makes use of the undocumented Ext.Direct.TID property. Assuming that my.namespace.my_action.my_method is an Ext.Direct API call that has been properly configured:

// Set up a global object in which to store data about pending calls
pendingCalls = {};

.
.
.

// Make a call to the server-side routine, and queue the data
my.namespace.my_action.my_method( call_data );
pendingCalls[ Ext.Direct.TID ] = call_data;

.
.
.
//The handler of the Ext.direct.Provider's "data" event
onData = function( provider, data ) {
    if data.type == "rpc" {
        // Recover the original call_data
        call_data = pendingCalls[ data.tid ];

        // Do something with call_data and data.result
    }
}

I don't like using the private internals of the Ext.Direct class. Is there an official way to do this, using Ext.Direct's public interface?


The solution I posted in the question works, even though its undocumented. And since nobody's posted another way of doing this, I'll stick with it.


It probably did not exist at the time you asked, but in case anyone else is wondering:

When you make an ExtDirect call, you pass the arguments, a callback, scope and options.

Place your call_data into the options and get them back with each response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜