var storeAttach = Ext.create('Ext.data.Store', {
autoLoad: false,
model: 'Tgoodsimage',
proxy: {
type: 'ajax',
url: '<%=basePath%>goods/goods!goodsAttach.do',
reader: { type: 'json', root: 'dataList' }
},
listeners: {
load: function (store, options) {
var fieldset = {
// Fieldset in Column 1 - collapsible via toggle button
xtype:'fieldset',
columnWidth: 0.5,
title: '附属图片',
collapsible: true,
defaultType: 'textfield',
defaults: {anchor: '100%'},
layout: 'anchor',
// items :[field ]
items :[ ]
// items :[field, {
// fieldLabel : "预览图片",
// xtype: 'box', //或者xtype: 'component',
// autoEl: {
// width: 300, //图片宽度
// tag: 'img', //指定为img标签
<%-- src: '<%=basePath%>upload'+record.get('filePath') //指定url路径 --%>
// }
// } ]
}
if(store.getCount()>0){
for(var i=0;i<store.getCount();i++){
var record = store.getAt(i);
var field= {
margin:'10px',
xtype: 'fieldcontainer',
layout: { type: 'hbox' },
fieldDefaults: { labelAlign: 'right', labelWidth: 90, width: 290 },
//items: [inventoryField ]
items: [ {
}, {
xtype: 'filefield',
// name: 'attach['+i+']',
name: 'attach',
fieldLabel: '图片',
allowBlank: ((action == 'update') ? true : false),
anchor: '100%',
buttonText: '选择图片',
emptyText: '--请选择图片--',
value:record.get('filePath')
},{
xtype : 'button',
text : '删除',
iconCls : 'silk_page_add',
handler : function(button ) {
Ext.Ajax.request({
url: '<%=basePath%>goods/goods!delAttach.do',
method: 'post',
async: true,
params: { attachId: record.get('id') },
success: function(response){
var result = Ext.decode(response.responseText);
if(result.success){
alert(result.msg);
button .up('fieldset').remove(button.up('fieldcontainer'));
}else{
alert(result.msg);
}
}
});
}
},{
xtype:'panel',
height:60,
// margin-left: 100,
html:'<img style=" width: 100;" src="<%=basePath%>upload'+record.get('filePath')+'"/>'
} ]
};
fieldset.items.push(field);
imgCount++;
// console.log(field);
// field.down('[name^=attach]').setValue(record.get('filePath'));
}
var _form = formPanel;
_form.add(fieldset);
}
// var type = store.getAt(0).data['data.type'];
// cboType.setValue(storeType.getAt(type-1));
}
}
});
待完善:修改附属图片时候,会全部删除附属图片。原因就是,无法在修改图片的时候,传相应的ID到后台,从而不知道是修改的哪张图片。
怎么才能传ID到后台?