<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shadow &#38; Honnix &#187; ajax</title>
	<atom:link href="http://honnix.com/blog/archives/tag/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://honnix.com/blog</link>
	<description>she&#039;s growing up</description>
	<lastBuildDate>Sun, 15 Jan 2012 10:44:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>如何在Lift里用javascript的confirm</title>
		<link>http://honnix.com/blog/archives/566</link>
		<comments>http://honnix.com/blog/archives/566#comments</comments>
		<pubDate>Thu, 13 May 2010 15:30:48 +0000</pubDate>
		<dc:creator>honnix</dc:creator>
				<category><![CDATA[Lift]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[anchor]]></category>
		<category><![CDATA[confirm]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://honnix.com/blog/?p=566</guid>
		<description><![CDATA[使用Lift的SHtml.a()设计ajax调用的时候，老版本的Lift不支持给onclick加入用户自己定义的javascript方法，新版本的有了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /** * Create an anchor tag around a body which will do an AJAX call and invoke the function * * @param jsFunc -- the user function that will be executed. This function will receive as last parameter * the&#8230;]]></description>
			<content:encoded><![CDATA[<p>使用Lift的SHtml.a()设计ajax调用的时候，老版本的Lift不支持给onclick加入用户自己定义的javascript方法，新版本的有了。</p>

<div class="wp_codebox"><table><tr id="p5663"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p566code3"><pre class="scala" style="font-family:monospace;"><span style="color: #00ff00; font-style: italic;">/**
   * Create an anchor tag around a body which will do an AJAX call and invoke the function
   *
   * @param jsFunc -- the user function that will be executed. This function will receive as last parameter
   *                  the function that will actually do the ajax call. Hence the user function can decide when
   * 				  to make the ajax request.
   * @param func - the function to invoke when the link is clicked
   * @param body - the NodeSeq to wrap in the anchor tag
   * @param attrs - the anchor node attributes
   */</span>
  <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> a<span style="color: #F78811;">&#40;</span>jsFunc<span style="color: #000080;">:</span> Call, func<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;;</span> JsCmd, body<span style="color: #000080;">:</span> NodeSeq, attrs<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>String, String<span style="color: #F78811;">&#41;</span><span style="color: #000080;">*</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Elem <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    attrs.<span style="color: #000000;">foldLeft</span><span style="color: #F78811;">&#40;</span>fmapFunc<span style="color: #F78811;">&#40;</span>contextFuncBuilder<span style="color: #F78811;">&#40;</span>func<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>name <span style="color: #000080;">=&gt;;</span>
            <span style="color: #000080;">&lt;</span>a onclick<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;{deferCall(Str(name&quot;</span> href<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;javascript://&quot;</span><span style="color: #000080;">&gt;</span><span style="color: #F78811;">&#123;</span>body<span style="color: #F78811;">&#125;</span><span style="color: #000080;">&lt;</span>/a<span style="color: #000080;">&gt;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span> <span style="color: #000080;">%</span> <span style="color: #000080;">_</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>对于jsFunc可以这样理解：<br />
用户定义了一个方法：</p>

<div class="wp_codebox"><table><tr id="p5664"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p566code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066; font-weight: bold;">delete</span><span style="color: #009900;">&#40;</span>toDelete<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Delete?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    toDelete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>那么jsFunc可以这样定义：Call(&#8220;delete&#8221;)，Lift会把它生成的ajax方法作为最后一个参数传递给delete方法。</p>
]]></content:encoded>
			<wfw:commentRss>http://honnix.com/blog/archives/566/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

