Javascript 在.NET3.5中,将ExtJS与Asp.net和WCF结合使用的最佳实践是什么?
如何从ExtJS表单保存数据?将数据从业务层加载到表单或网格中?我仅通过web服务将ExtJs与ASP.NET结合使用。如果您愿意在没有“页面”和所有这些东西的情况下工作,它就可以正常工作。我很可能找到了最好的解决方案Javascript 在.NET3.5中,将ExtJS与Asp.net和WCF结合使用的最佳实践是什么?,javascript,asp.net-ajax,extjs,Javascript,Asp.net Ajax,Extjs,如何从ExtJS表单保存数据?将数据从业务层加载到表单或网格中?我仅通过web服务将ExtJs与ASP.NET结合使用。如果您愿意在没有“页面”和所有这些东西的情况下工作,它就可以正常工作。我很可能找到了最好的解决方案 对于我来说,我使用了ASHX页面来直接推送XML,然后使用ExtJS数据读取器来读取。。然后,假设使用表单等,我将表单数据直接推回到另一个ASHX页面,以询问/发布到DB。。如果我知道最好的方法,那就糟糕了——但它适合我,而且看起来非常快速和稳定,最重要的是它更容易遵循/调试 下
对于我来说,我使用了ASHX页面来直接推送XML,然后使用ExtJS数据读取器来读取。。然后,假设使用表单等,我将表单数据直接推回到另一个ASHX页面,以询问/发布到DB。。如果我知道最好的方法,那就糟糕了——但它适合我,而且看起来非常快速和稳定,最重要的是它更容易遵循/调试 下面是一些代码示例,如果它有帮助的话。。。希望不要妨碍 获取数据 正如您将看到的,获取数据的URL是一个简单的ASHX(GenericHandler).NET页面,该页面将直接返回XML
// Define the core service page to get the data (we use this when reloading)
var url = '/pagedata/getbizzbox.ashx?duration=today';
var store = new Ext.data.GroupingStore(
{
// Define the source for the bizzbox grid (see above url def). We can pass (via the slider)
// the days param as necessary to reload the grid
url: url,
// Define an XML reader to read /pagedata/getbizzbox.ashx XML results
reader: new Ext.data.XmlReader(
{
// Define the RECORD node (i.e. in the XML <record> is the main row definition), and we also
// need to define what field is the ID (row index), and what node returns the total records count
record: 'record',
id: 'inboxID',
totalRecords: 'totalrecords'
},
// Setup mapping of the fields
['inboxID', 'messageCreated', 'subject', 'message', 'messageOpened', 'messageFrom', 'messageFromID', 'groupedMessageDate']),
// Set the default sort scenario, and which column will be grouped
sortInfo: { field: 'groupedMessageDate', direction: "DESC" },
groupField: 'groupedMessageDate'
}); // end of Ext.data.store
将数据从表单发布到后端
同样,请注意定义的第一部分中的url。。要将已发布的表单数据发送回另一个ASHX页面,然后发送到DB
// ---------------------------------------------------------------------------------------------
// DEFINE THE REPLY FORM
// This is used to show the existing message details, and allows the user to respond
// ---------------------------------------------------------------------------------------------
var frmReply = new Ext.form.FormPanel(
{
baseCls: 'x-plain',
labelWidth: 55,
method: 'POST',
url: '/postdata/bizzbox_message_reply.ashx',
items: [
{
xtype: 'textfield',
readOnly: true,
fieldLabel: 'From',
name: 'messageFrom',
value: selectedRow.get('messageFrom'),
anchor: '100%' // anchor width by percentage
},
{
xtype: 'textfield',
readOnly: true,
fieldLabel: 'Sent',
name: 'messageCreated',
value: selectedRow.get('messageCreated'),
anchor: '100%' // anchor width by percentage
},
{
xtype: 'textarea',
selectOnFocus: false,
hideLabel: true,
name: 'msg',
value: replyMessage,
anchor: '100% -53' // anchor width by percentage and height by raw adjustment
},
// The next couple of fields are hidden, but provide FROM ID etc which we need to post a new/reply
// message to
{
xtype: 'textfield',
readOnly: true,
fieldLabel: 'subject',
name: 'subject',
hidden: true,
hideLabel: true,
value: selectedRow.get('subject')
},
{
xtype: 'textfield',
readOnly: true,
fieldLabel: 'FromID',
name: 'messageFromID',
hidden: true,
hideLabel: true,
value: selectedRow.get('messageFromID')
},
{
xtype: 'textfield',
readOnly: true,
fieldLabel: 'InboxID',
name: 'inboxID',
hidden: true,
hideLabel: true,
value: selectedRow.get('inboxID')
}]
}); // end of frmReply
最后一位实际将上述表单汇总到后端。。。
此窗口使用上面的表单定义实际提交数据。。在ASHX页面中,数据只是作为一个已发布的表单传递-即,您可以通过普通的Request.form对象进行访问。。我知道有一种方法可以将表单数据以XML的形式发布到ASHX页面,尽管出于我的目的,它不是必需的——非常简单的表单
// ---------------------------------------------------------------------------------------------
// REPLY WINDOW - uses the frmReply as defined previously on stargate atlantis
// ---------------------------------------------------------------------------------------------
var win = new Ext.Window(
{
title: selectedRow.get("subject"),
width: 500,
height: 300,
minWidth: 300,
minHeight: 200,
layout: 'fit',
plain: false,
bodyStyle: 'padding:5px;',
buttonAlign: 'right',
items: frmReply,
// Add the action buttons for the message form
buttons: [
{
// When the user replies, we send the form results to the posting ashx which updates
// the DB etc, and returns the result
text: 'reply',
handler: function()
{
frmReply.getForm().submit({ waitMsg: 'Sending your message now...' });
}
},
{
text: 'close',
handler: function()
{
// We need to close the message window
win.close();
}
}]
});
// Show the message detail window
win.show();
再一次,希望这能有所帮助-我花了几个星期才做到!!可能对编码来说太老了 我们使用ExtJS和WCF的组合获得了巨大的成功。我们使用常规的Asp.net页面来提供主题、身份验证和基本页面UI,然后ExtJS在客户端启动,向WCF服务发出GETs,该服务返回纯简单的裸格式JSON(不带“d”属性)。真的很棒。WCF服务也是同一web应用程序的一部分,因此在整个web应用程序中使用了用户身份验证/授权 我们遇到的唯一问题是返回文件的页面和同时使用Ajax和常规Asp.net回发的页面。我们必须在这些往返中处理ExtJS控件持久性。但我们还是成功了
ExtJS+WCF工作得很好,我建议任何使用类似于Windows应用程序的web应用程序的人使用它。只是不要使用常规asp.net页面功能和Ajax组合使项目过于复杂。或者UpdatePanels。如果您有兴趣通过gwt使用java开发Extjs,您可以在这个Extjs gwt gxt博客上了解更多信息。也许对你有帮助
你能提供一些例子吗?你能说得更具体些吗?你到底需要什么?博客已经移动了,下面是新的url:
// ---------------------------------------------------------------------------------------------
// REPLY WINDOW - uses the frmReply as defined previously on stargate atlantis
// ---------------------------------------------------------------------------------------------
var win = new Ext.Window(
{
title: selectedRow.get("subject"),
width: 500,
height: 300,
minWidth: 300,
minHeight: 200,
layout: 'fit',
plain: false,
bodyStyle: 'padding:5px;',
buttonAlign: 'right',
items: frmReply,
// Add the action buttons for the message form
buttons: [
{
// When the user replies, we send the form results to the posting ashx which updates
// the DB etc, and returns the result
text: 'reply',
handler: function()
{
frmReply.getForm().submit({ waitMsg: 'Sending your message now...' });
}
},
{
text: 'close',
handler: function()
{
// We need to close the message window
win.close();
}
}]
});
// Show the message detail window
win.show();