<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>ExtJS開発メモ</title>
<link>https://ameblo.jp/ext-memo/</link>
<atom:link href="https://rssblog.ameba.jp/ext-memo/rss20.xml" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
<description>ExtJSでの困りごと等、忘備録。</description>
<language>ja</language>
<item>
<title>ExtJS MVCアーキテクチャを導入する最短ルート</title>
<description>
<![CDATA[ Ruby on Rails以降、ネイティブでがりがり書いたり自前フレームワークを作ったりでなく、既存のフレームワークに仕様を乗っけて手早く開発するスタイルが定着しましたね。<br><br><br>Javascript界隈でも Backbone.js, Knockout.js などのフレームワーク導入を耳にすることが多くなりました。<br><br><br>ExtJSでも ver4.0 以降より、機能種別に分割実装する「MVCアーキテクチャ」という仕組みが導入されています。<br>詳細はこちら：<a href="http://docs.sencha.com/extjs/4.2.0/#!/guide/application_architecture" target="_blank">http://docs.sencha.com/extjs/4.2.0/#!/guide/application_architecture</a><br><br><br><h4>今回は、"世界で最もミニマムなExt-MVC導入"が目標です。</h4><br><br>コントローラとビューを一つずつ用意し、モデルは省略します。<br><br><br>ソースファイルは、下記の計４つです。<br>　・HTMLファイル<br>　・アプリケーション定義ファイル<br>　・コントローラ<br>　・ビュー<br><br><br>１）HTMLファイル - [sample.html]<br>　アプリケーションを起動するHTMLファイルです。<br><br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130511/src.html" width="500" height="270"></div><br><br>２）アプリケーション定義ファイル - [app.js]<br>　各種設定・使用するコントローラを定義し、起動時の初期処理を行います。<br>　このファイルは、どれほど機能が増えても基本的に一つしか無いはずです。<br><pre class="brush: js;"><br>// 自動ファイル読込機能を有効化する。<br>Ext.Loader.setConfig({ enabled: true });<br><br>// アプリケーション'App'の定義<br>Ext.application({<br><br>&nbsp; &nbsp; // Viewport自動生成機能を無効化する。<br>&nbsp; &nbsp; autoCreateViewport: false,<br><br>&nbsp; &nbsp; // アプリケーション名を'App'にセット。<br>&nbsp; &nbsp; name: 'App',<br><br>&nbsp; &nbsp; // アプリケーションフォルダパスを指定する。<br>&nbsp; &nbsp; appFolder: './app',<br><br>&nbsp; &nbsp; // このアプリケーションで使用するコントローラ名を指定する。<br>&nbsp; &nbsp; controllers: [ 'Main' ],<br><br>&nbsp; &nbsp; // アプリケーション起動イベントハンドラ<br>&nbsp; &nbsp; launch: function() {<br><br>&nbsp; &nbsp; &nbsp; &nbsp; // Viewを生成・表示する。<br>&nbsp; &nbsp; &nbsp; &nbsp; Ext.create('App.view.main.Window',{}).show();<br>&nbsp; &nbsp; }<br>});<br></pre><br>３）コントローラ - [Main.js]<br>　機能を束ねる中枢です。<br>　使用するビュー・モデル等を定義し、イベントハンドリングを行います。<br><pre class="brush: js;"><br>// コントローラ'Main'の定義<br>Ext.define('App.controller.Main', {<br><br>&nbsp; &nbsp; // コントローラは'Ext.app.Controller'を継承させる。<br>&nbsp; &nbsp; extend: 'Ext.app.Controller',<br><br>&nbsp; &nbsp; // このコントローラで使用するViewを指定する。<br>&nbsp; &nbsp; views : ['main.Window'],<br><br>&nbsp; &nbsp; // コントローラ起動イベントハンドラ<br>&nbsp; &nbsp; init &nbsp;: function() {<br><br>&nbsp; &nbsp; &nbsp; &nbsp; // イベント関連付けを行う。<br>&nbsp; &nbsp; &nbsp; &nbsp; this.control({<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // XType='mainwindow'のオブジェクト配下、action='ok'のボタンを<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // イベントハンドル対象とする。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; ※オブジェクト指定方法の詳細は、'Ext.ComponentQuery'をご確認ください。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.ComponentQuery<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'mainwindow button[action=ok]': {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // クリックイベントをハンドルする。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; click: function(btn){<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ボタンが所属するViewから、ボタンの上位方向に対して、<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // XType='window'のオブジェクトを検索・取得する。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var win &nbsp; = btn.up('window'),<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // window配下のオブジェクトの中から、XType='form'の<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // オブジェクトを検索・取得する。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form &nbsp;= win.down('form'),<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // フォーム配下にある項目の値を一括取得する。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = form.getValues();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Values JSON: '+ Ext.JSON.encode(value));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; }<br>});<br></pre><br><br>４）ビュー - [Window.js]<br>　見た目に関するコードです。<br><pre class="brush: js;"><br>// ビュー'main.Window'の定義<br>Ext.define('App.view.main.Window', {<br>&nbsp; &nbsp; extend &nbsp;: 'Ext.window.Window',<br>&nbsp; &nbsp; alias &nbsp; : 'widget.mainwindow',<br>&nbsp; &nbsp; title &nbsp; : 'ウインドウ',<br>&nbsp; &nbsp; items &nbsp; : [<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xtype: 'form',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; items: [<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xtype &nbsp; &nbsp; : 'textfield',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name &nbsp; &nbsp; &nbsp;: 'textbox',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel: 'テキストボックス',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin &nbsp; &nbsp;: '5 5 5 5'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; ],<br>&nbsp; &nbsp; buttons : [<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text &nbsp;: 'OK',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action: 'ok'<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; ]<br>});<br></pre><br><br><br>それぞれ機能別の力関係としては、<br>　・アプリケーション定義が複数のコントローラを支配下に置く。<br>　・コントローラが複数のビュー、モデル(今回は割愛)を支配下に置く。<br>のような、３階層の構造になっています。<br><br><br><br>ファイルの配置は下記のようにします。<br><br><pre><br>htdocs<br>&nbsp; +- app<br>&nbsp; | &nbsp; &nbsp;+- controller<br>&nbsp; | &nbsp; &nbsp;| &nbsp; &nbsp;+- Main.js<br>&nbsp; | &nbsp; &nbsp;+- view<br>&nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; +- main<br>&nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+- Window.js<br>&nbsp; +- ext<br>&nbsp; | &nbsp; &nbsp;+- locale<br>&nbsp; | &nbsp; &nbsp;| &nbsp; &nbsp;+- ext-lang-ja.js<br>&nbsp; | &nbsp; &nbsp;+- resources<br>&nbsp; | &nbsp; &nbsp;| &nbsp; &nbsp;+- (以下割愛)<br>&nbsp; | &nbsp; &nbsp;+- ext-all.js<br>&nbsp; +- sample.html<br>&nbsp; +- app.js<br></pre><br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130511%2Fimg%2Ffiles.jpg"><br><br><br><br>さて、これでブラウザから sample.html へアクセスすると、<br>テキストボックスが一つだけのポップアップウインドウが表示されます。<br>"OK"ボタンをクリックすると、入力した値をJSONで表示します。<br><br>実際に動作する様子は、こちらです。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130511/sample.html" width="500" height="270"></div><br><br><br>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11528927807.html</link>
<pubDate>Sun, 12 May 2013 11:27:56 +0900</pubDate>
</item>
<item>
<title>ExtJSで出来ること</title>
<description>
<![CDATA[ Javascriptをベースにしたライブラリ／フレームワークは、JQuery, Prototype.js, Backbone.js など、<br>数多くのプロダクトがあります。<br><br>それら中で、ExtJSの特徴・立ち位置は、果たしてどんな所にあるのでしょうか？<br><br><br><h4>ExtJSの持ち味は、「統一感」です。</h4><br><br>ExtJSの最大の特徴は、UIで一般的に使われる"部品"が、あらかじめ用意されている点にあります。<br><br>ボタン・テキストボックスから、グリッド・グラフ描画・タブ切替など、アプリケーション製作に必要な"部品"は<br>ひと通り揃っています。<br><br>例えばJQueryプラグインのように、あちこちからかき集めた雑多でちぐはぐなUI／独自のプロパティ・メソッドに<br>悩まされることはありません。<br><br>ExtJSの"部品"は組織的に統括・管理されているためルック＆フィールが統一されており、アプリケーション全体を通して<br>一貫した操作感をユーザーに提供することが出来ます。<br><br><br>それらの"部品"を組み合わせ、積み上げて行くと、例えばこんな画面を作ることができます。<br>登録ボタンをクリックすると、画面に入力した値がJSONフォーマットで表示されます。<br>入力にエラーがあるときは、項目に赤いアンダーラインが表示されます。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130507/sample1.html" width="550" height="380"></div><br><br><br>ソースコードはこちらです。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130507/src1.html" width="550" height="2765"></div><br><br>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11526179202.html</link>
<pubDate>Tue, 07 May 2013 23:58:47 +0900</pubDate>
</item>
<item>
<title>日本語に対応するには</title>
<description>
<![CDATA[ さて。<br><a src="http://ameblo.jp/ext-memo/entry-11521003535.html">ここまでで、</a>ひとまずExtJSが動くようになりました。<br><br>しかし実は、このままでは先々コーディングを進めて行く上で、ちょっとだけ不都合があります。<br><br>すこし先走って、コードを書き進めてみます。<br>ポップアップウインドウの中に、テキストボックスを配置してみました。<br><br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130502/src1.html" width="550" height="690"></div><br><br><br>実行してみると、ポップアップ・ウインドウ内のテキストボックスに赤いアンダーラインが表示されます。<br>入力内容にエラーがあるときのしるしです。<br><br>ここで、テキストボックスにマウスオーバーしてみると...<br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130502%2Fimg%2Ferr1.jpg"><br><br><br><br>こんなふうに、エラーメッセージが英語表記になっているんですね。<br><br><br><br>しかしご安心ください。<br><br>ExtJSは標準パッケージの中に、多くの言語に対応したリソースファイルが同梱されています。<br><br><br>どこにあるかと言いますと、解凍したzipパッケージの中の <strong>「locale」フォルダ</strong> です。<br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130502%2Fimg%2Flocale.jpg"><br><br><br><br>さっそく、読み込んでみましょう。<br><br><br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130502/src2.html" width="550" height="760"></div><br><br><br><br>8行目、"ext-lang-ja.js" を読み込むように修正しました。<br><br><br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130502%2Fimg%2Ferr2.jpg"><br><br><br><br>はい、エラーメッセージが日本語になりました！<br><br><br><br><br><br>実際の動作はこちら。<br><br>---日本語未対応状態---<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130502/sample1.html" width="350" height="200"></div><br><br><br><br>---日本語に対応した状態---<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130502/sample2.html" width="350" height="200"></div><br><br><br><br>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11522581232.html</link>
<pubDate>Thu, 02 May 2013 16:09:00 +0900</pubDate>
</item>
<item>
<title>ExtJS4.2を導入する最短ルート</title>
<description>
<![CDATA[ 世界で最も手数が少ない、ExtJS4.2 の導入手順をご紹介します。<br><br><br>ダウンロードして、配置して、コードを書く。これだけです！<br><br><h4><br>１）ExtJSをダウンロード・解凍する。</h4>2013/04/30 現在、下記URLからGPLv3ライセンスのオープンソース版ExtJS4.2.0 がダウンロードできます。<br><a src="http://www.sencha.com/products/extjs/download/">http://www.sencha.com/products/extjs/download/</a><br><br>※画面上中央の緑ボタンでなく、中央左-"Working in Open Source?" の下の青い「Download」ボタンです。<br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130430%2Fimg%2F02.jpg"><br><br>Downloadボタンをクリックすると、「ext-4.2.0-gpl.zip」がダウンロードされます。<br><br>zipを解凍すると、「ext-4.2.0.663」フォルダの中に多くのフォルダ／ファイルがあります。<br><br><br>しかし、ひとまず必要なものは下記の　<strong>３つ</strong>　だけです。<br><br>　・ext-all.js ファイル<br>　・locale フォルダ<br>　・resources フォルダ<br><br><br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130430%2Fimg%2F01.jpg"><br><br><br><h4>２）Webサーバから見える場所に配置する。</h4>Webサーバのドキュメントルートに "ext" という名前のフォルダを作り、前述３つのファイル／フォルダをコピーします。<br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130430%2Fimg%2F05.jpg"><br><br><br><h4>３）ExtJSを組み込んだコードを書く。</h4>ドキュメントルートの <a src="http://ameblo.jp/ext-memo/entry-11520994301.html">index.html を、このように</a>書きます。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130430/src.html" width="550" height="300"></div><br><br><br><br><img src="https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Fume05rw.ddo.jp%2Fextsrcs%2F20130430%2Fimg%2F04.jpg"><br><br><br><h4>４）ブラウザで動作確認</h4>ローカルホストをブラウザから見てみましょう。<br><br>下のように小さなポップアップ・ウインドウが出てきたら、成功です。<br><br><div id="sample" class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130430/sample.html" width="550" height="300"></div><br>↑ウインドウはマウスで動かしたり、「×」ボタンで消したりできます。<br><br><br><br><br><br>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11521003535.html</link>
<pubDate>Tue, 30 Apr 2013 01:51:28 +0900</pubDate>
</item>
<item>
<title>世界で最も短いExtJS実装</title>
<description>
<![CDATA[ 世界で最も短いExtJS実装 -&nbsp;ポップアップウインドウを表示する。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130430/src.html" width="550" height="300"></div><br><br><br><br>こんなポップアップ・ウインドウが表示されます。<br><br><div class="ifbuilder" src="http://ume05rw.ddo.jp/extsrcs/20130430/sample.html" width="550" height="300"></div><br><br>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11520994301.html</link>
<pubDate>Tue, 30 Apr 2013 01:35:22 +0900</pubDate>
</item>
<item>
<title>Extのクラス定義について</title>
<description>
<![CDATA[ Javascriptはオブジェクト指向言語です。しかし、"クラス"という概念はありません。<br><br>そのせいか、JavaやC#のようなオブジェクト指向言語に慣れたプログラマでも、<br>Javascriptのオブジェクト指向概念を理解するのに少し手間取ることがあります。<br><br>その点ExtJSでは、トラッドなオブジェクト指向言語に準じて"クラス"の概念を導入しています。<br><br>ExtJSでのクラス定義は、こんなふうに書きます。<br><br><pre class="brush: js;"><br>Ext.define('クラス名'', {<br>&nbsp; &nbsp; プロパティ名: プロパティ初期値,<br>&nbsp; &nbsp; メソッド名: function(引数){<br>&nbsp; &nbsp; &nbsp; &nbsp; 処理;<br>&nbsp; &nbsp; }<br>});<br></pre><br><br>定義したクラスを元にインスタンスを取得するときは、2種類の方法があります。<br><br><h4>Ext.createを使う</h4><br><pre class="brush: js;"><br>var obj = Ext.create('クラス名', {});<br></pre><br><h4>Javascriptネイティブの、new演算子を使う</h4><br><pre class="brush: js;"><br>var obj = new クラス名();<br></pre><br><br><br><br>Java／C#出身でJavascriptを習得したい人など、ExtJSなら多少違和感が払拭できるかもしれません。
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11517611207.html</link>
<pubDate>Wed, 24 Apr 2013 19:34:19 +0900</pubDate>
</item>
<item>
<title>ExtJS4.1の入れ子Form対策</title>
<description>
<![CDATA[ <p>ExtJS4.0 -&gt; 4.1 になって、BasicForm.getValuesメソッドから入れ子Form内のフィールドが取得されるように変わった。</p><br><br><br><p>明細データ入力用テンプレやら、複合カスタムコントロールやらを作ったとき、中身のフィールドが全部取れてしまう。困った。</p><br><br><br><p>ソースを読むと、Ext.ComponentQueryで取ってきている。</p><br><br><br>ExtJS4.1.1 - src/form/Basic.js：350行目 <br><pre class="brush: js; sourcecode"><br>getFields: function() {<br>    var fields = this._fields;<br>    if (!fields) {<br>        fields = this._fields = new Ext.util.MixedCollection();<br>        fields.addAll(this.owner.query('[isFormField]'));<br>    }<br>    return fields;<br>},<br></pre><br><p><br><br></p><br><p>このExt.ComponentQuery、「XXを除外する」みたいな記述方法が分からない。うむむ。</p><br><br><br><p>しゃあなし、別途取得した除外フィールドを対象から外すようにする。</p><br><br><br><pre class="brush: js; sourcecode"><br>fields = new Ext.util.MixedCollection();<br>fields.addAll(this.owner.query('[isFormField]'));<br>excFields = new Ext.util.MixedCollection();<br>excFields.addAll(this.owner.query('form [isFormField]'));<br><br>for(i in excFields.items){<br>    fields.remove(excFields.items[i]);<br>}<br></pre><br><br><br><p>うーん、かっこ悪い。</p><br><p>ComponentQueryをもうちょっと勉強しよう。</p>
]]>
</description>
<link>https://ameblo.jp/ext-memo/entry-11515489534.html</link>
<pubDate>Sun, 21 Apr 2013 11:06:50 +0900</pubDate>
</item>
</channel>
</rss>
