<?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>Real Beat &#187; javascript</title>
	<atom:link href="http://nobu666.com/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://nobu666.com</link>
	<description>Keep drinking, Keep listening to music, Go fuck yourself</description>
	<lastBuildDate>Thu, 19 Jan 2012 04:57:28 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>jQuery + jTemplatesを使って、setIntervalで定期的に新しいデータを取得し、要素の上に追加していく方法</title>
		<link>http://nobu666.com/2009/11/22/793.html</link>
		<comments>http://nobu666.com/2009/11/22/793.html#comments</comments>
		<pubDate>Sun, 22 Nov 2009 08:43:39 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://nobu666.com/?p=793</guid>
		<description><![CDATA[はまったので忘れないうちにメモ。 $(&#8220;#piyopiyo&#8221;).processTemplate(data) とかやると、id=&#8221;piyopiyo&#8221;な要素の内容が全部置き換わ &#8230;<p class="read-more"><a href="http://nobu666.com/2009/11/22/793.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>はまったので忘れないうちにメモ。</p>
<p>$(&#8220;#piyopiyo&#8221;).processTemplate(data) とかやると、id=&#8221;piyopiyo&#8221;な要素の内容が全部置き換わってしまうので、古いデータが消えてしまう。たとえばTwitterクライアントみたいなものを作ろうと思ったら、定期的に新しいtimelineをとってきたら、古いデータを残しつつ、新しいものだけ上に出てきてほしい。</p>
<p>以下のようにすることで、id=&#8221;piyo&#8221;配下のclass=&#8221;moge&#8221;にデータがたまっていく。空のdivを一個用意して、そこにprocessTemplateで新しいデータを入れていく。<a href="http://twitter.com/hideaki_t/">@hideaki_t</a>、ありがとうございました。</p>
<pre class="brush: jscript; title: ;">
&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-jtemplates.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function() {
      hoge.count=1;
      $(&quot;#piyo &gt; .moge &gt; div:first&quot;).setTemplate(&quot;{#foreach $T as r}&lt;div class='hogera'&gt;{$T.r.id}&lt;/div&gt;{#/for}&quot;);
      hoge.show();
      window.setInterval(function(){
        hoge.show();
      }, 5000);
    });
    var hoge = {
      show:function() {
        var data = &quot;[{id:&quot; + hoge.count++ + &quot;}]&quot;;
        var t = $(&quot;#piyo &gt; .moge &gt; div:first&quot;);
        t.after(t.children());
        t.processTemplate(eval(data));
      }
    }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;piyo&quot;&gt;&lt;div class=&quot;moge&quot;&gt;&lt;div /&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2009/11/22/793.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

