为什么不是我行获取添加到我的表? [英] Why isn't my row getting added to my table?

查看:130
本文介绍了为什么不是我行获取添加到我的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的这篇文章创建用户在多行单个条目表单上输入的方式。什么样的作家在做什么,我在做什么不同的是,我把我的田地到表中。我的问题是,我没有得到插进我的表新行。我的猜测是,脚本没有找到 #editorRows ,但因为我仍然只有学习jQuery的我不是100%肯定。

我的HTML只显示相关部分

 <&字段集GT;
    <传奇>请求详情及LT; /传说>
    <表>
        < TBODY ID =editorRows>
            < TR><第i日期和LT; /第i个百分位>时间和LT; /第i个百分位>时间要求< /第i个百分位>请求类型< /第i个百分位>< /第i ;< / TR>
            &所述; TR类=editorRow>
                < TD> ...< / TD>
                < TD> ...< / TD>
                < TD>< A HREF =#类=deleteRow>< IMG SRC =../../图像/ site_icons / 16 / 69.png称号=删除ALT =删除BORDER =0/>< / A>< / TD>
            < / TR>        < / TBODY>
    < /表>    < P>< A HREF =/ LeaveRequest / BlankRequestedDayRowID =的addItem>添加白天< / A>< / P>
< /字段集>

我的jQuery的code:

 <脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){
        $(#的addItem)。点击(函数(){
            $阿贾克斯({
                网址:this.href,
                缓存:假的,
                成功:功能(HTML){$(#editorRows)追加(HTML)。 }
            });
            返回false;
        });
        $(a.deleteRow)。生活(点击,函数(){
            $(本)。家长(tr.editorRow:第一),删除();
            返回false;
        });
    });
< / SCRIPT>

在/ LeaveRequest / BlankRequestedDayRow的code被调用,所以我的猜测是,code不知道在哪里把它。 BlankRequestedDayRow补充说:

 < TR类=editorRow>
                < TD> ...< / TD>
                < TD> ...< / TD>
                < TD>< A HREF =#类=deleteRow>< IMG SRC =../../图像/ site_icons / 16 / 69.png称号=删除ALT =删除BORDER =0/>< / A>< / TD>
            < / TR>

BlankRequestedDay的完整code的要求:

 <%@控制语言=C#继承=System.Web.Mvc.ViewUserControl< EmployeePayroll.ViewModels.LeaveRequestRow>中%GT;
<%@导入命名空间=EmployeePayroll.Helpers%GT;&所述; TR类=editorRow>
    <使用%(Html.BeginCollectionItem(requestedDays))
       {%GT;
        < TD><%= Html.HiddenFor(型号=> model.DaysRequested.RequestId)%GT;<%= Html.EditorFor(型号=> model.DaysRequested.DateOfLeave.Date)%GT;< / TD>
        < TD><%= Html.EditorFor(型号=> model.DaysRequested.DateOfLeave.TimeOfDay)%GT;< / TD>
        < TD><%= Html.TextBoxFor(型号=> model.DaysRequested.HoursRequested,新{大小= 6})%GT;< / TD>
        < TD><%= Html.DropDownListFor(型号=> model.DaysRequested.RequestType,
            新的SelectList(Model.LeaveRequestType,值,文本,Model.DaysRequested.RequestType)(选择))%>< / TD>
        < TD>< A HREF =#类=deleteRow>< IMG SRC =../../图像/ site_icons / 16 / 69.png称号=删除ALT =删除BORDER =0/>< / A>< / TD>
    <%}%GT;
< / TR>


解决方案

你检查,如果你的AJAX调用返回的东西吗?

与Firefox,你可以使用萤火的控制台检查通话。

I am using this article to create a way for users to enter in multiple rows on a single entry form. The difference of what the author is doing and what I am doing is that I am putting my fields into a table. The problem I have is that I am not getting new rows inserted into my table. My guess is that the script isn't finding #editorRows but since I am still only learning jQuery I am not 100% sure.

My HTML showing only relevant parts

<fieldset>
    <legend>Request Details</legend>
    <table>
        <tbody id="editorRows">
            <tr><th>Date</th><th>Time</th><th>Hours Requested</th><th>Request Type</th><th></th></tr>
            <tr class="editorRow">
                <td>...</td>
                <td>...</td>
                <td><a href="#" class="deleteRow"><img src="../../images/site_icons/16/69.png" title="Delete" alt="Delete" border="0" /></a></td>
            </tr>

        </tbody>
    </table>

    <p><a href="/LeaveRequest/BlankRequestedDayRow" id="addItem">Add Day</a></p>
</fieldset>

My jQuery Code:

<script type="text/javascript">
    $(document).ready(function() {
        $("#addItem").click(function() {
            $.ajax({
                url: this.href,
                cache: false,
                success: function(html) { $("#editorRows").append(html); }
            });
            return false;
        });
        $("a.deleteRow").live("click", function() {
            $(this).parents("tr.editorRow:first").remove();
            return false;
        });
    });
</script>

The code in /LeaveRequest/BlankRequestedDayRow is being called, so my guess is that the code doesn't know where to put it. BlankRequestedDayRow adds:

            <tr class="editorRow">
                <td>...</td>
                <td>...</td>
                <td><a href="#" class="deleteRow"><img src="../../images/site_icons/16/69.png" title="Delete" alt="Delete" border="0" /></a></td>
            </tr>

The full code of BlankRequestedDay as requested:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EmployeePayroll.ViewModels.LeaveRequestRow>" %>
<%@ Import Namespace="EmployeePayroll.Helpers"%>

<tr class="editorRow">
    <% using (Html.BeginCollectionItem("requestedDays"))
       { %>
        <td><%= Html.HiddenFor(model => model.DaysRequested.RequestId) %><%= Html.EditorFor(model => model.DaysRequested.DateOfLeave.Date)%></td>
        <td><%= Html.EditorFor(model => model.DaysRequested.DateOfLeave.TimeOfDay)%></td>
        <td><%= Html.TextBoxFor(model => model.DaysRequested.HoursRequested, new { size = 6 })%></td>
        <td><%= Html.DropDownListFor(model => model.DaysRequested.RequestType, 
            new SelectList(Model.LeaveRequestType, "Value", "Text", Model.DaysRequested.RequestType), "(Select)")%></td>
        <td><a href="#" class="deleteRow"><img src="../../images/site_icons/16/69.png" title="Delete" alt="Delete" border="0" /></a></td>
    <% } %>
</tr>

解决方案

Did you check if you're ajax call returns something ?

With firefox, you can use firebug's console to inspect the call.

这篇关于为什么不是我行获取添加到我的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆