2

以下に、2 つのフィールドを持つ Ext.form.Panel があります。モデルで、データを持つ 2 つのランダム フィールドを選択しました。それらはフォームにレンダリングされていません。このコードでは、Extjs フレームワークで MVC を使用していないことに注意してください。 これらのフィールドをレンダリングするにはどうすればよいですか? store.data.toSource() からの関連する出力を貼り付けて、実際にストアにデータがあり、レコードが 1 つしかないことを示しました。もう少し大きな解像度で画像を表示するには、画像を右クリックして別のタブで表示します。

注: .toSource() は Mozilla Firefox でのみ機能します

フォームを作成した後にこれを実行しようとしましたが、うまくいきませんでした:

taskForm.getForm().loadRecord(store.getAt(0));

コード:

    var taskForm = Ext.create('Ext.form.Panel', {
        title: 'Task',
        id: 'form1',
        width: 600,
        height: 200,
        bodyPadding: 10,
        renderTo: 'TaskEditForm',
        store: store,
        style: {
            'position': 'fixed',
            'top': '100px',
            'left': '10px'
        },

        items: [{
            xtype: 'label',
            labelAlign: 'right',
            name: 'project_id',
            fieldLabel: 'Project ID',
            width: 100
        }, {
            xtype: 'label',
            labelAlign: 'right',
            name: 'user_responsible',
            fieldLabel: 'User',
            width: 100
        }],

        buttons: [{
            text: 'Save Task Detail',
            handler: function (btn) {

                alert(store.data.toSource());

            }

        }]
    });

ここに画像の説明を入力

========

編集:@エヴァン

このコードでは、以下のエラーが発生します。

taskForm.getForm().loadRecord(store.getAt(0));

エラー:

TypeError: record is undefined

...

return this.setValues(record.data);  // ext-all-debug.js (line 109529)

行 109529:

loadRecord: function(record) {
  this._record = record;
  return this.setValues(record.data);
}, 
4

1 に答える 1

3

ドキュメントを読みましたか?store.data一連のMixedCollectionレコードを保持する です。loadメソッドのドキュメントには次のように書かれています。

サーバーから Ext.form.Basic のフィールドへのデータのロードを処理するクラス。

ランダムなパラメーターを投げるだけで、何かが機能することを期待することはできません。

おそらくあなたが望むのは:

form.getForm().loadRecord(store.getAt(0)); // Load the first store record into the form

于 2013-06-04T22:59:20.360 に答える