2011-12-21 98 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

为组件初始化

相关问题