1

私は MVC アーキテクチャを使用しています (MVC のドキュメントを確認しましたが、ここでまだ迷っています)、ラベルにレコードを入力する方法を知る必要があります。私は、これをストアが行わなければならないことを知っています。

ストアから値をロードしましたが、何らかの理由でパネルに表示できません。これが私のコードです。

例/本のほとんどは、ラベルではなくグリッドに表示する方法を示しています(同じロジックでなければならないことはわかっていますが、迷っています)。また、DB/JSON ファイルに書き込み、値を表示しない方法を示します。

ラベル テキストに COUNTRYNAME を表示する必要があります。これは、これを理解するために私が行っているサンプルコードです.誰かが私を助けることができますか?

Ext.define ('ProjectDisplayExample.model.Country',{
    extend: 'Ext.data.Model',
    //
    fields:['countryid','countryname']
    //
});

お店

Ext.define('ProjectDisplayExample.store.Country',{
    extend:'Ext.data.Store',
    model:'ProjectDisplayExample.model.Country',
    remoteGroup:true,
    proxy: {
        actionMethods : {
            read   : 'POST',
        },
        type: 'ajax',
        url : '/server/country.php'
    }   
});

見る

Ext.define('ProjectDisplayExample.view.CountryWindow', {
    extend: 'Ext.window.Window',
    alias: 'widget.countrywindow',
    ...........

    initComponent: function() {
        var st = Ext.getStore('Country');
        st.load();
        this.items = [
        {
            items: [
            {
                xtype: 'panel',
                region: 'north',
                items: [{
                    xtype: 'label',
                    // NEED TO DISPLAY COUNTRT NAME FROM THE STORE HERE
                }]
            }]
}

アップデート

var store = ... // Your store
store.on('load', function() {
    // here store is loaded and you can do anything you want with it
    console.log('store is loaded. number of records = ', store.getCount());
}, this, { single: true });

store.load; // I ADDED THIS LINE.................... <---------

更新 2

this.items = [
            {
                items: [
                {
                    xtype: 'panel',
                    region: 'north',
                    items: [{
                        xtype: 'label',
                        name : f
                    }]
                }]
4

1 に答える 1

3

あなたの質問を正確に解決するためのコードサンプルは投稿しませんが、いくつかのポイントを示します。

  • Store には配列またはレコードが含まれます。give me country nameなので、お店だけでは言えません。最初にレコードを取得する必要があります (例: var r = store.getAt(0)、その後でのみ countyname field を取得できます) var f = r.get('countryname')

  • Load()メソッドは非同期であるため、コードのどこかで実行するだけで、次の行でストアの準備ができていると想定できます。load次のようなイベントにサブスクライブする必要があります。

    var store = ... // Your store
    store.on('load', function() {
        // here store is loaded and you can do anything you want with it
        console.log('store is loaded. number of records = ', store.getCount());
    }, this, { single: true });
    store.load();
    
  • のようなラベルは、xtype: label実際には ExtJ で使用されることはほとんどありません。そのパネルに正確に何を表示しようとしていますか? とにかく...ストアからデータを取得した後、またはその他の方法を使用update()setValue()てコンポーネントを更新できます。

お役に立てれば...

于 2012-07-08T16:59:09.793 に答える