2012-02-19 11 views
0

私はExtJS 4を初めて使用しており、MVCスタイルの単純なアプリケーションを実装しようとしています。ドキュメントは本当にうれしいですが、これはフォームパッケージガイドで扱っているトピックの1つですが、私の場合はうまくいかないようです。ExtJS 4 MVCアプリケーション:フォーム定義されていないエラー

アプリは基本的に記事を作成、編集、削除できます。作成と編集はポップアップウィンドウにあります。 ポップアップウィンドウには、テキストフィールドとhtml-editorを含むフォームが含まれています。 下のリンクをクリックしてください、これは私が「窓」ここ

http://www.freeimagehosting.net/mjig7私は モデルを書いたコードであるに送信ボタンをクリックしてGoogle Chromeのコンソールでのエラーは、次のとおりです。

Ext.define('AM.model.Article', { 
    extend: 'Ext.data.Model', 
    fields: ['name', 'data'], 
    proxy: { 
     type: 'rest', 
     url: 'users/data', 
     reader: { 
      type: 'json', 
      root: 'myJaxBean', 
      successProperty: 'success' 
     }, 
     writer: { 
      type: 'json' 
     } 
    } 
}); 

ビュー:

Ext.define('AM.view.New', { 
    extend: 'Ext.window.Window', 
    alias : 'widget.new', 
    title : 'New Article', 
    autoShow: true, 
    fieldDefaults: { 
     labelAlign: 'top', 
     msgTarget: 'side' 
    }, 
    layout: 'fit', 
    bodyStyle:'padding:5px 5px 0', 
    width: '70%', 
    height: '40%', 
    initComponent: function() { 
     this.items = [ 
      { 
       xtype: 'form', 
       anchor: '99%', 
       items: [ 
        { 
         xtype: 'textfield', 
         name : 'name', 
         fieldLabel: 'Article Name', 
         anchor: '99%' 
        }, 
        { 
         xtype: 'htmleditor', 
         name : 'data', 
         fieldLabel: 'Article', 
         anchor: '99% -25' 
        } 
       ], 
       buttons: [ 
       { 
        text: 'Submit', 
        handler: function() { 
         var form = this.up('form').getForm(), // get the basic form 
          record = form.getRecord(); // get the underlying model instance 
         if (form.isValid()) { // make sure the form contains valid data before submitting 
          form.updateRecord(record); // update the record with the form data 
          record.save({ // save the record to the server 
           success: function(user) { 
            Ext.Msg.alert('Success', 'User saved successfully.') 
           }, 
           failure: function(user) { 
            Ext.Msg.alert('Failure', 'Failed to save user.') 
           } 
          }); 
         } else { // display error alert if the data is invalid 
          Ext.Msg.alert('Invalid Data', 'Please correct form errors.') 
         } 
        } 
       }, 
       { 
        text: 'Cancel', 
        scope: this, 
        handler: this.close 
       } 
      ] 
      } 
     ], 


     this.callParent(arguments); 
    } 
}); 

、最終的には、ウィンドウのviを作る私のコントローラのコードsible

コントローラー:

..... 

'viewport > panel > panel > tbar button[action=newarticle]' :{ 
       click: this.newArticle 
      }, 
.... 

    newArticle: function(button){ 
     var view = Ext.widget('new'); 
    }, 

私が何か間違ったことをやっている場合は、正しい方向に私を指すください。 ありがとうございます。

答えて

0

ドキュメントgetRecord()を確認してください:

はあなたのようなので、それはあなたが任意のレコードをロードしていないことは明らかだ loadRecord

を介してロードされた最後のExt.data.Modelインスタンスを返します。 getRecord()は未定義を返します。そしてあなたはあなたのエラーをさらに引き起こしています。

+0

うん、私はそれを理解した。今度は、Ext.create.Recordを使って新しいレコードを作成し、値を割り当てる前にフォームにロードします。 努力をいただきありがとうございます。 –

関連する問題