<?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>ExtJSで楽しくRIA業務アプリ開発 &#187; DOM</title>
	<atom:link href="http://extjs.blog.sus4.co.jp/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://extjs.blog.sus4.co.jp</link>
	<description>株式会社sus4 開発チーム</description>
	<lastBuildDate>Wed, 01 Jun 2011 09:32:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ExtJS入門　DomHelperの使い方3　位置指定の追加と削除</title>
		<link>http://extjs.blog.sus4.co.jp/2010/02/25/extjs-domhelper-insert-remove/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/02/25/extjs-domhelper-insert-remove/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 06:47:22 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[DomHelper]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[勉強会]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=385</guid>
		<description><![CDATA[DomHelperで要素を追加するの追加項目です。
DomHelperで要素の追加を行うときappendでは対象の要素の子の要素として要素を追加しましたが、insertBefore,insertAfterでは対象の要素の前後に要素を追加します。]]></description>
			<content:encoded><![CDATA[<p>DomHelperで要素を追加するの追加項目です。<br />
DomHelperで要素の追加を行うときappendでは対象の要素の子の要素として要素を追加しましたが、insertBefore,insertAfterでは対象の要素の前後に要素を追加します。<br />
今回はあえてパネルを使わずにやってみます。</p>
<p>DomHelperについてはこちらにサンプルがあります。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/01/14/extjs-tutorial13-domhelper1/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門13 Ext.DomHelperの使い方</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/01/14/extjs-tutorial14-domhelper2/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門14　DomHelperの使い方2</a></li>
</ul>
<p><span id="more-385"></span></p>
<p><strong>サンプルコード3 DomHelperを使った位置指定の追加とDomQueryを使った削除</strong></p>
<p><strong>・html</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　DOMHelperの使い方 DOMの追加と削除&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;domhelper-sample4.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;body&quot; style=&quot;padding:15px;&quot;&gt;
    &lt;h1&gt;位置を指定して追加する&lt;/h1&gt;
    &lt;div id=&quot;beforeBtn&quot; style=&quot;float:left;&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;afterBtn&quot; style=&quot;float:left;&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;bothBtn&quot; style=&quot;float:left;&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;removeBtn&quot; style=&quot;float:left;&quot;&gt;&lt;/div&gt;
    &lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;insert-target&quot;&gt;
    &lt;hr/&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>・javascript</strong></p>
<pre class="brush: js; ">

Ext.onReady(function(){
    //初期値の設定
    var bcnt = 0;
    var acnt = 0;
    var bias = 3;
    var bchar = &#039;M&#039;;
    var achar = &quot;W&quot;;

    var before = function(target) {
        Ext.DomHelper.insertBefore(&#039;insert-target&#039;,{
            cls:&#039;add&#039;,
            html:String.leftPad(bchar,bcnt * bias,bchar)
        });
        bcnt++;
    };

    var after = function(target) {
        Ext.DomHelper.insertAfter(&#039;insert-target&#039;,{
            cls:&#039;add&#039;,
            html:String.leftPad(achar,acnt * bias,achar)
        });
        acnt++;
    };

    var remove = function(target) {
        //任意のDOMを見つけるにはDomQueryを使う。ここではCSSクラスがaddのもの全て。
        var elems = Ext.DomQuery.select(&#039;.add&#039;);
        Ext.each(elems,function(o,cnt,array){
            Ext.removeNode(o);
        });
        bcnt = acnt = 0;
    };

    //ボタンを作成
    new Ext.Button({
        renderTo:&#039;beforeBtn&#039;,
        text:&quot;追加(Before)&quot;,
        handler:before
    });

    new Ext.Button({
        renderTo:&#039;afterBtn&#039;,
        text:&quot;追加(After)&quot;,
        handler:after
    });

    new Ext.Button({
        renderTo:&#039;bothBtn&#039;,
        text:&quot;前後に追加&quot;,
        handler:function() {
            before();
            after();
        }
    });

    new Ext.Button({
        renderTo:&#039;removeBtn&#039;,
        text:&quot;追加したDOMを削除&quot;,
        handler:remove
    });
});
</pre>
<p><strong>・実行結果</strong><br />
<div id="attachment_479" class="wp-caption aligncenter" style="width: 310px"><a href="http://extjs.blog.sus4.co.jp/files/2010/02/SS-2010.02.25-14.42.41.png" title="DomHelper DOMの追加と削除" rel="lightbox[385]"><img src="http://extjs.blog.sus4.co.jp/files/2010/02/SS-2010.02.25-14.42.41-300x178.png" alt="DomHelper DOMの追加と削除" title="DomHelper DOMの追加と削除" width="300" height="178" class="size-medium wp-image-479" /></a><p class="wp-caption-text">DomHelper DOMの追加と削除</p></div></p>
<p>ボタンを4つ作って各ボタンに、直前に追加、直後に追加、両方に追加、削除を割り当てています。ボタンが押されると、罫線の前後の所定の位置に要素を追加します。<br />
またこのサンプルではDomQueryクラスを使って追加要素を探して、削除する処理も追加しています。DomHelperはDOMの生成や追加を行いますが、DomQueryはDOMツリーから任意の要素を探すことができます。今回はDomQueryの使い方について詳しく解説しませんが、追加した要素をCSSのクラスから探し出す処理を行っています。</p>
<p>グリッドパネルやツリーパネルの構築はブロックを組み立てるようなイメージですが、Ext.Panelは真っ白のキャンバスに絵を描いていく感覚に近いと気がします。パネルの中のDOMを自由に操れると、ExtJSの派手なUIの裏にある奥深いDOMの世界を体感できるようになります。ExtJSでDOMをいじって初めてExtJSをいじったことになると何処かで聞いたことがありますね。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F02%2F25%2Fextjs-domhelper-insert-remove%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%80%E3%80%80DomHelper%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B93%E3%80%80%E4%BD%8D%E7%BD%AE%E6%8C%87%E5%AE%9A%E3%81%AE%E8%BF%BD%E5%8A%A0%E3%81%A8%E5%89%8A%E9%99%A4"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/02/25/extjs-domhelper-insert-remove/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

