2011-12-21 48 views
0

我爲多個文件上傳創建了一個自定義字段,問題出在第一步,我甚至無法將選定的文件添加到網格,你能告訴我什麼是我的代碼問題嗎?我看着螢火蟲,並沒有Java腳本錯誤。爲什麼不添加記錄出現在網格中?

Ext.define('VDOA.form.fields.Attachment', { 
extend: 'Ext.form.FieldContainer', 
mixins: {field: 'Ext.form.field.Field'}, 
requires: ['Ext.form.field.Base'], 
alias: 'widget.attachment', 
layout: 'fit', 
constructor: function() 
{ 
    var me = this; 

     me.items = [ 
       { 
        itemId: 'grid', 
        anchor: '100%', 
        width: 300, 
        height: 100, 
        xtype: 'gridpanel', 
        layout: 'fit', 
        autoRender: true, 
        autoShow: true, 
        tbar: [ 
         { 
          itemId: 'add', 
          hideLabel: true, 
          buttonOnly: true, 
          buttonText: 'Browse a file', 
          xtype: 'fileuploadfield' 
         } 
        ], 
        columns: [ 
         { 
          dataIndex: 'Id', 
          xtype: 'gridcolumn', 
          text: 'File Id' 
         }, 
         { 
          dataIndex: 'Title', 
          xtype: 'gridcolumn', 
          text: 'File Name' 
         } 
        ] 
       } 
     ]; 

     me.callParent(arguments); 

    var store = Ext.create('Ext.data.ArrayStore', { 
      fields: [ 
       {name: 'Id', type: 'int'}, 
       {name: 'Title', type: 'string'}, 
       {name: 'IsUploading', type: 'bool'} 
      ], 
      data: [] 
     }); 

     me.down('#grid').store = store; 

     me.down('#add').on('change', function(o, e){ 
      store.add({Id: Ext.id(), Title: o.value, IsUploading: true}); 
      store.load(); 
     }); 
}, 

getErrors: function() { 
    return []; 
}, 

validate: function() { 
    return true; 
}}); Ext.onReady(function() { 
Ext.QuickTips.init(); 

var win = new Ext.Window({ 
    width:500 
    ,id:'winid' 
    ,height:300 
    ,layout:'fit' 
    ,border:false 
    ,closable:false 
    ,title:'File Upload' 
    ,items:[{ 
     xtype:'form' 
     ,frame:true 
     ,labelWidth:100 
     ,items:[{ 
      name: 'Title', 
      xtype: 'textfield', 
      fieldLabel: 'Title', 
      allowBlank: false, 
      anchor: '100%' 
     }, 
     { 
      name: 'Attachment', 
      xtype: 'attachment', 
      fieldLabel: 'Attached Files' 
     }] 
    }] 
    ,buttons:[{ 
     text:'Submit' 
     ,handler:function() { 
      Ext.getCmp('form').getForm().submit(); 
     } 
    }] 
}); 
win.show();}); 
+0

你可以顯示你的成功代碼。我嘗試使用類似php的多重上傳功能,但現在不工作 – freestyle 2013-06-21 08:42:51

回答

1
Ext.define('VDOA.form.fields.Attachment', { 
     extend:'Ext.form.FieldContainer', 
     mixins:{field:'Ext.form.field.Field'}, 
     requires:['Ext.form.field.Base'], 
     alias:'widget.attachment', 
     layout:'fit', 
     constructor:function() { 
      var me = this, 
       store = Ext.create('Ext.data.ArrayStore', { 
        fields:[ 
         {name:'Id', type:'int'}, 
         {name:'Title', type:'string'}, 
         {name:'IsUploading', type:'bool'} 
        ], 
        data:[] 
       }); 
      me.items = [ 
       { 
        itemId:'grid', 
        anchor:'100%', 
        width:300, 
        height:100, 
        store: store, // link store there... 
        xtype:'gridpanel', 
        layout:'fit', 
        height:400, 
        autoRender:true, 
        autoShow:true, 
        tbar:[ 
         { 
          itemId:'add', 
          hideLabel:true, 
          buttonOnly:true, 
          buttonText:'Browse a file', 
          xtype:'filefield' 
         } 
        ], 
        columns:[ 
         { 
          dataIndex:'Id', 
          xtype:'gridcolumn', 
          text:'File Id' 
         }, 
         { 
          dataIndex:'Title', 
          xtype:'gridcolumn', 
          text:'File Name' 
         } 
        ] 
       } 
      ]; 

      me.callParent(arguments); 

      //me.down('#grid').store = store; 

      me.down('#add').on('change', function (o, e) { 
       me.down('#grid').store.add({Id:Ext.id(), Title:o.value, IsUploading:true}); 
       // store.load(); // remove it - it set data = [] as it was initialized before 
      }); 
     }, 

     getErrors:function() { 
      return []; 
     }, 

     validate:function() { 
      return true; 
     }}); 
    Ext.onReady(function() { 
     Ext.QuickTips.init(); 

     var win = new Ext.Window({ 
      width:500, id:'winid', height:300, layout:'fit', border:false, closable:false, title:'File Upload', items:[ 
       { 
        xtype:'form', frame:true, labelWidth:100, items:[ 
        { 
         name:'Title', 
         xtype:'textfield', 
         fieldLabel:'Title', 
         allowBlank:false, 
         anchor:'100%' 
        }, 
        { 
         name:'Attachment', 
         xtype:'attachment', 
         fieldLabel:'Attached Files' 
        } 
       ] 
       } 
      ], buttons:[ 
       { 
        text:'Submit', handler:function() { 
        Ext.getCmp('form').getForm().submit(); 
       } 
       } 
      ] 
     }); 
     win.show(); 
    }); 

在這段代碼中失敗。

正如我之前所說的,店鋪未與其網格成功關聯。當onchange事件出現時,商店重新加載默認數據= []。 享受! :)

0

嘗試沒有

store.load(); 

您onChange處理。

另外,檢查有關商店。它是否成功鏈接到商店?

+0

我嘗試了'store.load()',但它不起作用。我如何檢查其鏈接或不鏈接?我有照明插件。我可以使用它嗎? – 2011-12-21 09:42:16

+0

另一個想法:是否改變事件發生? – erlrange 2011-12-21 10:10:29

+0

我找不到任何錯誤。你可以測試這些代碼並告訴我你是否有同樣的問題? – 2011-12-21 10:13:49

0

還..好的做法是執行嵌套組件和插件上

initComponent

方法

喜歡的東西

initComponent:函數(){ var me = this; /* ------ */me.callParent(arguments); }

並使用

Ext.apply

y或

Ext.applyIf

爲組件初始化

相關問題