检索表单数据的最佳策略是什么?客户端ajax/server
最近,我被介绍了Ajax表单数据处理,包括使用jTemplates来保证一些可重复性和jQuery,这是一个很棒的库 但我有点困惑。对于表单用户交互,我使用Ajax调用并处理纯HTML标记。所以如果我想在加载表单时绑定表单数据,我需要通过jQuery/JS使用Ajax进行绑定。这对我来说并不好我觉得onLoad初始化应该只在服务器上进行。然而,接下来我需要找到一些方法来公开表单标记,以便以后的Ajax交互将是直接的 例如,如果我想在服务器上绑定一些列表,有什么控件可以处理这个问题,以便我以后可以使用Ajax添加/删除项目? 我希望我把我的观点讲清楚。谢谢你的帮助 @Rex 做例子的方法很简单。 做一些中继器控制检索表单数据的最佳策略是什么?客户端ajax/server,ajax,callback,interaction,Ajax,Callback,Interaction,最近,我被介绍了Ajax表单数据处理,包括使用jTemplates来保证一些可重复性和jQuery,这是一个很棒的库 但我有点困惑。对于表单用户交互,我使用Ajax调用并处理纯HTML标记。所以如果我想在加载表单时绑定表单数据,我需要通过jQuery/JS使用Ajax进行绑定。这对我来说并不好我觉得onLoad初始化应该只在服务器上进行。然而,接下来我需要找到一些方法来公开表单标记,以便以后的Ajax交互将是直接的 例如,如果我想在服务器上绑定一些列表,有什么控件可以处理这个问题,以便我以后可以
<table id="suppliers" >
<tbody>
<asp:Repeater ID = "rptSuppliers" runat = "server">
<ItemTemplate>
<tr style = "padding:10px;" class = "supplier" tag = '<%# Eval("ID") %>' id = 'supplier_<%# Eval("ID") %>'>
<td style = "width:200px;">ספק: <%# Eval("Supplier.Group.GroupName") %></td>
<td style = "width:200px;">איש קשר: <%# Eval("Supplier.Profile.ProfileData.FullName")%></td>
<td>מחיר:
<%--כדי שהולדיאציה תבוצע כיאות לשדה צריך להיות שם ומזהה זהים אבל ייחודיים--%>
<input class = "required price" name ="price<%# Eval("Supplier.ID") %>" id = "price<%# Eval("Supplier.ID") %>" type="text" value = '<%# Eval("Price","{0:n2}") %>' min ="0" style ="width:60px;"/>
<input class ="supplier_id" type ="hidden" value = '<%# Eval("Supplier.ID") %>' />
</td>
<td style = "padding-right:10px;">
<img src ="../../Images/remove40_32x32.gif" height ="16" width = "16" title = 'הסר' style = "float:right;" id = "sremove"
onclick = "removeClick(this)"
onmouseout = "removeOut(this)"
onmouseover = "removeOver(this)" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
最重要的是客户端。
您可以将一些相同的内容添加到转发器中,该添加由mTamplate jquery插件生成
<script type="text/html" id="suppliers_tmpl">
<tr style = "padding:10px;" class = "supplier" tag = '<#= ID #>' id = 'supplier_<#= ID #>'>
<td style = "width:200px;">ספק: <#= Supplier #></td>
<td style = "width:200px;">איש קשר: <#= Contact #></td>
<td>מחיר:
<input class = "required price" name ="price<#= SupplierID #>" id = "price<#= SupplierID #>" type="text" value = '<#= Price #>' min ="0" style ="width:60px;"/>
<input class ="supplier_id" type ="hidden" value = '<#= SupplierID #>' />
</td>
<td style = "padding-right:10px;"><img src ="../../Images/remove40_32x32.gif" height ="16" width = "16" title = 'הסר' style = "float:right;" id = "sremove"
onclick = "removeClick(this)"
onmouseout = "removeOut(this)"
onmouseover = "removeOver(this)" />
</td>
</tr>
</script>
ספק:
איש קשר:
מחיר:
然后如果你想在你的桌子上加上这个填充物
function UpdatesupplierItem(supplier) {
// Retrieve the Item template
var template = $("#suppliers_tmpl").html();
// Parse the template and merge stock data into it
var html = parseTemplate(template, supplier);
// Create jQuery object from gen'd html
var newItem = $(html);
var item_id = "supplier_" + supplier.SupplierID;
//נוסיף פריט רק במידה ואיננו קיים
var origItem = $("#" + item_id);
if (origItem.length < 1)
newItem.appendTo("#suppliers tbody");
else
origItem.after(newItem).remove();
return newItem;
功能更新供应商项目(供应商){
//检索项目模板
var template=$(“#供应商_tmpl”).html();
//解析模板并将股票数据合并到其中
var html=parseTemplate(模板,供应商);
//从生成的html创建jQuery对象
var newItem=$(html);
var item_id=“supplier”+supplier.SupplierID;
//נוסיף פריט רק במידה ואיננו קיים
var origItem=$(“#”+项目id);
如果(原始长度<1)
新增项目。附录(“供应商主体”);
其他的
origItem.after(newItem.remove();
返回新项目;
}
使jquery可以访问html元素(通过id或类)。
去做吧
更多信息
在那里,您可以获得一些到源代码的链接,并且有很多示例。实现这一点的最简单方法是使用更新面板 如果您将中继器放在更新面板中,当您的删除回发被触发时,更新面板将只刷新该更新面板中的内容 因此,使用中继器构造行,添加delete按钮,然后从数据库中删除该行 如果您在没有ajax(整页回发)的情况下让它工作,然后添加更新面板,那么它“应该”可以直接工作 请看一个例子 问候
加文你不是唯一一个感到困惑的人对不起,但这个问题的语法让我感到困惑。我什么都不懂,但我试着纠正拼写和语法。希望下一个来的人不会那么困惑。。。尽管我仍然认为答案不太可能……为理解这一点的努力而喝彩+1Bravo感谢您尝试理解这一点+1.
function UpdatesupplierItem(supplier) {
// Retrieve the Item template
var template = $("#suppliers_tmpl").html();
// Parse the template and merge stock data into it
var html = parseTemplate(template, supplier);
// Create jQuery object from gen'd html
var newItem = $(html);
var item_id = "supplier_" + supplier.SupplierID;
//נוסיף פריט רק במידה ואיננו קיים
var origItem = $("#" + item_id);
if (origItem.length < 1)
newItem.appendTo("#suppliers tbody");
else
origItem.after(newItem).remove();
return newItem;