[mochikit] defferedlist, how to know the index of a particular deffered in the list
I have a situation where I have an array of arbitray length consisting of keywords. For each keyword, I fire off a doSimpleXMLHttpRequest(). I then use DeferredList() to create a list of all the Deferred objects and I add a callback. Now my problem is, how do I know from my callback function that the result comes from the seventh request I made, or the ninth, etc.? This is because I need to possibly modify one of the keywords in the array I used to orginally generate the requests. So I need to be able to relate the keyword to the request result. Thanks for any clarification. Everything else works great. I've done a lot of looking and I just can't get it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: defferedlist, how to know the index of a particular deffered in the list
Hi there, On 6/15/07, Yves [EMAIL PROTECTED] wrote: I then use DeferredList() to create a list of all the Deferred objects and I add a callback. Now my problem is, how do I know from my callback function that the result comes from the seventh request I made, or the ninth, etc.? The callback to the deferredlist will receive one parameter, an array with the result of each deferred. Each element of that array is again a two-element array, the first element being a boolean, true if that deferred was successful and false otherwise and the second element is the result of that deferred. To clarify, the result is whatever a regular callback to that deferred would have received. If the index of the deferred doesn't suffice to find the keyword, you can make sure you receive the keyword like this: function combine_key_with_result(key, result) { return {key: key, result: result}; } var xhr_deferreds = map(function (key) { var d = do_your_xhr_call_and_return_deferred(key); d.addCallback(partial(combine_key_with_result, key)); return d; }, your_keyword_list); var dl = new DeferredList(xhr_deferreds); dl.addCallback(function (results_list) { forEach(result_list, function (dl_result) { var success = dl_result[0]; var key = dl_result[1].key; var result = dl_result[1].result; // now do your thing here :) }) }); hth, Arnar --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
Ok. Like I say, this is not very clear to me right now, and I'm trying to create an option list for a drop-down. Let me put up my shot-in-the-dark example, then maybe someone can correct me: // add a single value/text option to drop-down: OPTION(null, {'value': '123', 'text': 'some text'}); Trying to create this: option value=123some text/option and a bunch more if everything goes well I know that is completely wrong. This may be explained in the docs, but I'm not seeing it. The example for building a table element is not translating to an option. How does it know what element to use? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
On 6/15/07, hotani [EMAIL PROTECTED] wrote: Ok. Like I say, this is not very clear to me right now, and I'm trying to create an option list for a drop-down. Let me put up my shot-in-the-dark example, then maybe someone can correct me: // add a single value/text option to drop-down: OPTION(null, {'value': '123', 'text': 'some text'}); Trying to create this: option value=123some text/option and a bunch more if everything goes well The first argument is attributes, additional arguments are contents. OPTION({'value': '123'}, some text); -bob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
Great, thanks Bob. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
And here is a real working example in all its glory: appendChildNodes($('id'), OPTION({'value':val}, txt)); where 'val' is an id from the database and 'txt' is its description. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
Good to know, thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---