2012-08-13 9 views
6

Tôi đã có:ExtJS - Mẫu gửi mã

win = desktop.createWindow({ 
    id: 'admin-win', 
    title: 'Add administration users', 
    width: 740, 
    height: 480, 
    iconCls: 'icon-grid', 
    animCollapse: false, 
    constrainHeader: true, 
    xtype: 'form', 
    bodyPadding: 15, 
    url: 'save-form.php', 
    items: [{ 
     xtype: 'textfield', 
     fieldLabel: 'Field', 
     name: 'theField' 
    }], 

    buttons: [{ 
     text: 'Submit', 
     handler: function() { 
      var form = this.up('form').getForm(); 
      if (form.isValid()) { 
       form.submit({ 
        success: function (form, action) { 
         Ext.Msg.alert('Success', action.result.message); 
        }, 
        failure: function (form, action) { 
         Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response'); 
        } 
       }); 
      } 
     } 
    }] 
}); 

Và các nút không hoạt động. Nó tạo ra lỗi - this.up ('form') là không xác định. Làm thế nào tôi có thể gọi getForm() trong mã như vậy?

CẬP NHẬT: Cảm ơn bạn đã trả lời rất nhanh! tôi đổi mã của bạn cho nhu cầu của tôi, đây là nó, và nó làm việc với máy tính để bàn Ví dụ:

win = desktop.createWindow({ 
    id: 'admin-win', 
    title: 'Add administration users', 
    width: 740, 
    iconCls: 'icon-grid', 
    animCollapse: false, 
    constrainHeader: true, 
    items: [{ 
     xtype: 'form', 
     bodyPadding: 15, 
     url: 'save-form.php', 
     items: [{ 
      xtype: 'textfield', 
      fieldLabel: 'Field', 
      name: 'theField' 
     }], 

     buttons: [{ 
      text: 'Submit', 
      handler: function() { 
       var form = this.up('form').getForm(); 
       if (form.isValid()) { 
        this.up().up().submit({ 
         success: function (form, action) { 
          Ext.Msg.alert('Success', action.result.message); 
         }, 
         failure: function (form, action) { 
          Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response'); 
         } 
        }); 
       } 
      } 
     }] 
    }] 
}); 
+0

Đây có phải là mã hoàn chỉnh của bạn? Desktop.createWindow làm gì? Tôi đang yêu cầu này bởi vì nó có vẻ như bạn đang cố gắng để crete một cửa sổ nhưng sử dụng Ext.form.Panel tùy chọn. – davidbuzatto

+0

Nó dựa trên Ví dụ về ExtJS Desktop. Tôi muốn tạo cửa sổ chỉ với biểu mẫu. –

+0

Vì vậy, bạn sao chép/dán mã này? – davidbuzatto

Trả lời

5

Như tôi đã nói, có vẻ như bạn có vấn đề với mã của bạn. Bạn đang đi qua Ext.form.Panel tùy chọn để một Ext.window.Window (Tôi giả định này bởi vì tên của phương pháp mà bạn đang gọi). Tôi đang viết một ví dụ với một cửa sổ cho bạn. Chỉ một lát thôi.

Nó đã sẵn sàng. Hãy xem:

Ext.create('Ext.window.Window', { 
    title: 'This is a Window with a Form', 
    height: 200, 
    width: 400, 
    layout: 'fit', 
    items: [{ // the form is an item of the window 
     id: 'admin-win', 
     title: 'Add administration users', 
     width: 740, 
     height: 480, 
     iconCls: 'icon-grid', 
     animCollapse: false, 
     constrainHeader: true, 
     xtype: 'form', 
     bodyPadding: 15, 
     url: 'save-form.php', 
     items: [{ 
      xtype: 'textfield', 
      fieldLabel: 'Field', 
      name: 'theField', 
      allowBlank: false 
     }], 
     buttons: [{ 
      text: 'Submit', 
      handler: function() { 
       var form = this.up('form').getForm(); 
       if (form.isValid()) { 
        form.submit({ 
         success: function(form, action) { 
          Ext.Msg.alert('Success', action.result.message); 
         }, 
         failure: function(form, action) { 
          Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response'); 
         } 
        }); 
       } else { 
        Ext.Msg.alert("Error!", "Your form is invalid!"); 
       } 
      } 
     }] 
    }] 
}).show(); 

jsFiddle: http://jsfiddle.net/davidbuzatto/vWmmD/

+0

Cảm ơn :-) Tôi đã cập nhật bài đăng đầu tiên của mình, vì tôi không có quyền trả lời cho các chủ đề của mình ;-) Tôi phải sửa đổi mã của bạn cho các nhu cầu của mình. –

+0

Bạn được hoan nghênh! Như tôi đã nói, bạn đã thực sự vượt qua Ext.form.Panel tùy chọn để Ext.window.Window :) ExtJS là rất tốt đẹp. Hãy xem tài liệu của nó vì nó rất hoàn chỉnh. – davidbuzatto