需要实现以下这种类似表格的效果,表格中所有的数据(多行数据)能够被提交到后台:
1.使用普通的js做表格可以实现,在extjs中只看到有Grid可以做类似效果,但是如果在grid中将所有行的数据提交到后台尚不清楚?2.另外:后台接口有要求,如果是多个联系人数据,各联系人需要使用index来区分,例如:contact[0].id=1&contact[0].name=mayun、contact[1].id=2&contact[1].name=mahuateng。
这种要求如果使用普通js可以实现,但是在ext中不知道如何是好?请大神给予解答。extgrid 多行数据提交, extgrid多行数据提交ext表格中提交多行数据
1.使用普通的js做表格可以实现,在extjs中只看到有Grid可以做类似效果,但是如果在grid中将所有行的数据提交到后台尚不清楚?2.另外:后台接口有要求,如果是多个联系人数据,各联系人需要使用index来区分,例如:contact[0].id=1&contact[0].name=mayun、contact[1].id=2&contact[1].name=mahuateng。
这种要求如果使用普通js可以实现,但是在ext中不知道如何是好?请大神给予解答。extgrid 多行数据提交, extgrid多行数据提交ext表格中提交多行数据
服务器端要求对没有modify的数据也需要提交,所以需要提交grid中的所有数据。
这种方式我已经尝试成功过,并且也按服务器端后台接口要求,将参数名称修改为含有index的方式(contact.id --> contact[0].id)。封装的数据最终是{contact[0].id:1}这种格式。但是,这种方式需要手动封装,ext中没有其它更好的办法直接提交grid的所有数据吗?
或者你不需要得到选中的,默认全部把gridpanel的store都传到后台,我这个是传id到后台的,只是给你一个例子,希望可以帮助你
//选中的数据
me=的是当前的gridpanel
var records = me.getSelectionModel().getSelection(); var store = me.getStore();
var currenIds = "";
for(var i=0;i<store.getCount();i++){
obj = store.getAt(i).raw.files || store.getAt(i).raw.archive;
currenIds+= obj.id+",";
}
谢谢你的热心回答,我们在删除数据时是使用的类似这种传递id参数的方式。但在这里我们是需要将grid中所有的数据提交到后台。
解决方法如下://Submit data using ajax
function submitData(action,form)
{
//Get the form values hash.
var paramsHash = form.getForm().getValues();
//Put the all association store values.
//All team.
teamStore.each(function(record,i){
var datas = record.data;
//Generate assocition object index
var index = "["+i+"]";
for(hashKey in datas)
{
var newHashKey = hashKey.replace(/\.fundTeam/,".fundTeam"+index);
paramsHash[newHashKey] = datas[hashKey];
}
});
var url = '<%=request.getContextPath()%>/object/xml.do?otype=foundation&action='+action;
Ext.Ajax.request({
url:url,
params: paramsHash,
success:function(response,opts)
{
var xmlDoc = response.responseXML;
var elements = Ext.DomQuery.select('xml[@result=true]',xmlDoc);
if(elements.length>0)
{
//Obtaining window position
var width = 120;
var msgContainer = form.getEl();
var x = (msgContainer.getWidth()/2)-(width/2);
var y = (msgContainer.getHeight()/2);
//show message
var win = new Ext.Window({
width:width,
x:x,
y:y,
title: '数据更新成功!',
closable: false
});
win.show();
//close message and redirect to list page
setInterval(function(){
win.close();
window.location.href = "fund.jsp";
}, 1500);
}
else
{
Ext.Msg.alert('失败', '数据更新失败:' + response.responseText);
}
}
});
}