<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: DWR Callback closures inside loops</title>
	<atom:link href="http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/</link>
	<description>My Blog, Take 4</description>
	<pubDate>Sat, 22 Nov 2008 04:54:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Paul</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-460</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Fri, 18 Jul 2008 13:30:56 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-460</guid>
		<description>Here is roughly how i got the looping callback to work... (this is specifically for dwr2.*)

function newClosure(someNum, someRef) {
  return function(x) {    	
          showResultsInBrowser(x, someNum);
    }     
}

function getServerResponses(){
	// some other stuff...
	var count = aJsVariableSomewhere;
	for(var k=1;k&#60;=count;k++){	
		closure = newClosure(k, {somevar : 'closure'+k});	
		remote.method("response"+k, closure);	
	}
}

function showResultsInBrowser(serverResponse, index){
// do some UI stuff
}</description>
		<content:encoded><![CDATA[<p>Here is roughly how i got the looping callback to work&#8230; (this is specifically for dwr2.*)</p>
<p>function newClosure(someNum, someRef) {<br />
  return function(x) {<br />
          showResultsInBrowser(x, someNum);<br />
    }<br />
}</p>
<p>function getServerResponses(){<br />
	// some other stuff&#8230;<br />
	var count = aJsVariableSomewhere;<br />
	for(var k=1;k&lt;=count;k++){<br />
		closure = newClosure(k, {somevar : &#8216;closure&#8217;+k});<br />
		remote.method(&#8221;response&#8221;+k, closure);<br />
	}<br />
}</p>
<p>function showResultsInBrowser(serverResponse, index){<br />
// do some UI stuff<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-459</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Wed, 16 Jul 2008 16:03:12 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-459</guid>
		<description>Lav,

This approach doesn't seem to work under pre v3.0 of DWR - I had the same problem - ie undefined index.

After lots &#38; lots of searching I eventually got it working by adapting Example 7 so that it would work from within a loop. (BTW: it also explains why the above approach doesnt work in Example 5)

See: http://blog.morrisjohns.com/javascript_closures_for_dummies.html

I hope someone finds this useful and it saves them some time.

Paul</description>
		<content:encoded><![CDATA[<p>Lav,</p>
<p>This approach doesn&#8217;t seem to work under pre v3.0 of DWR - I had the same problem - ie undefined index.</p>
<p>After lots &amp; lots of searching I eventually got it working by adapting Example 7 so that it would work from within a loop. (BTW: it also explains why the above approach doesnt work in Example 5)</p>
<p>See: <a href="http://blog.morrisjohns.com/javascript_closures_for_dummies.html" rel="nofollow">http://blog.morrisjohns.com/javascript_closures_for_dummies.html</a></p>
<p>I hope someone finds this useful and it saves them some time.</p>
<p>Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lav</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-435</link>
		<dc:creator>Lav</dc:creator>
		<pubDate>Wed, 07 May 2008 13:36:36 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-435</guid>
		<description>Hi,

In the following code, when I give an alert for 'this.index', it is displayed as undefined. 

Could you please help me.

	for(var i=0;i&#60;ids.length;i++) {
			var remoteCall = {
				index : i,
				callback : function(data) {
					fillTable(data, ids[this.index]);
				}
			};	
			PopulateParameterList.getAjaxPopulateParameterList(paramId,reportId,"",remoteCall);

Thank you</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>In the following code, when I give an alert for &#8216;this.index&#8217;, it is displayed as undefined. </p>
<p>Could you please help me.</p>
<p>	for(var i=0;i&lt;ids.length;i++) {<br />
			var remoteCall = {<br />
				index : i,<br />
				callback : function(data) {<br />
					fillTable(data, ids[this.index]);<br />
				}<br />
			};<br />
			PopulateParameterList.getAjaxPopulateParameterList(paramId,reportId,&#8221;",remoteCall);</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Lothian</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-433</link>
		<dc:creator>Nick Lothian</dc:creator>
		<pubDate>Tue, 06 May 2008 23:11:05 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-433</guid>
		<description>I can't see why it wouldn't - it's not specifically a DWR thing, more Javascript + Async calls</description>
		<content:encoded><![CDATA[<p>I can&#8217;t see why it wouldn&#8217;t - it&#8217;s not specifically a DWR thing, more Javascript + Async calls</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lav</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-432</link>
		<dc:creator>Lav</dc:creator>
		<pubDate>Tue, 06 May 2008 15:52:56 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-432</guid>
		<description>Does this pattern work in DWR version 2 ?</description>
		<content:encoded><![CDATA[<p>Does this pattern work in DWR version 2 ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hani Suleiman</title>
		<link>http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-10</link>
		<dc:creator>Hani Suleiman</dc:creator>
		<pubDate>Fri, 18 May 2007 18:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://nicklothian.com/blog/2007/05/18/dwr-callback-closures-inside-loops/#comment-10</guid>
		<description>Yeah, I just discovered this pattern too, the dwr docs sort of hint at it, but in a fairly oblique manner, sufficiently so that you don't feel like giving them any credit when you 'discover' this approach!</description>
		<content:encoded><![CDATA[<p>Yeah, I just discovered this pattern too, the dwr docs sort of hint at it, but in a fairly oblique manner, sufficiently so that you don&#8217;t feel like giving them any credit when you &#8216;discover&#8217; this approach!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.802 seconds -->
