LoginSignup
0
0

More than 5 years have passed since last update.

controllerの中でstoreを操作

Posted at

Sencha Touchのコントローラの中でストアを扱うための第一歩

過去のアプリケーションを再利用し、アプリケーションの起動時に表示されるメッセージボックスの文字列をストアの1個目の要素にする。

過去のアプリケーション
* caroucelコンポーネントの使い方
* storeのデータをcaroucelコンポーネントに表示
* 初めてのcontrollerの追加

app/controller/Players.jsのconfig.control内を以下のように書き換える

'main': {
    // initialize: 'sayGreeting'
    // アプリケーション初期化イベント発火時のメソッドを
    // sayGreetingからshowOneRecordに変更
   initialize: 'showOneRecord'
}

app/controller/Players.jsにshowOneRecordメソッドを追加する

showOneRecord: function() {
    var store = Ext.getStore('Players');
    var first_record = store.first().get('name');
    Ext.Msg.alert(first_record);
},
  • 2行目でストアを取得
  • 3行目では、2行目で取得したストアの最初の要素のnameキーの値を取得

この状態でapp/controller/Players.jsを保存した後に、例によってcarouseltestフォルダに移動して

python -m SimpleHTTPServer

のコマンドを打ってブラウザで http://0.0.0.0:8000 にアクセすることで以下の描画を行うアプリケーションを実行できます。

CarouselTest_and_CarouselTest.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0