2

テーブルからクーポンを「削除」できる顧客用の DotNetNuke モジュールを作成しました。リンクをクリックすると、jQuery を使用して Ajax POST が作成され、成功すると行が削除され (または少なくとも非表示になり)、CssClass が添付された成功メッセージが表示されます。行が削除された部分を除いて、すべてが正常に機能しています。DotNetNuke だけで、他の ASP.NET Web Forms/MVC プロジェクトではこの問題は発生していません。結局、テーブル全体が削除され、成功メッセージが表示されます。これが私のコードです:

<script language="javascript" type="text/javascript">

jQuery.noConflict();
var deletingCouponID = null;

function DeleteCoupon(_CouponID) {

    deletingCouponID = _CouponID;

    jQuery.post(
        "mylink.aspx",
        { CouponID: _CouponID },
        function (data) {

            if (data.Response == "Success") {
                alert("#row" + deletingCouponID);

                jQuery("#tblCoupons tbody tr.row" + deletingCouponID).remove();
                jQuery("#divAjaxMsg").html("<p>" + data.Message + "</p>");
                jQuery("#divAjaxMsg").addClass("NormalRed");
            }
            else {
                jQuery("#divAjaxMsg").html("<p>" + data.Message + "</p>");
                jQuery("#divAjaxMsg").addClass("NormalRed");
            }
        },
        "json"
    );
}

そしてHTML:

<div style="padding:1px">

<asp:Label runat="server" ID="lblMessage" ></asp:Label>

<div runat="server" id="divCouponList" >

    <div style="text-align: center">
        <h1>Coupon List</h1>
    </div>

    <div id="divAjaxMsg" />

    <table cellpadding="5px" id="tblCoupons">
        <thead>
            <tr>
                <th>Coupon ID</th>
                <th>Coupon Code</th>
                <th>Author</th>
                <th>Date Created</th>
                <th>Expiration Date</th>
                <th>Amount</th>
                <th>Min Purchase Amount</th>
                <th>Num Uses</th>
                <th>Max Uses</th>
                <th>Target User</th>
                <th>Target Product</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        <%
            string Sql = "SELECT * FROM MyTable WHERE Expired != 'True'";
            using (IDataReader Reader = DataProvider.Instance ().ExecuteSQL (Sql))
            {
                int Count = 0;
                while (Reader.Read ())
                {
                    ++Count;
        %>
                    <tr id="row<%= ((int)Reader["CouponID"]).ToString () %>">
                        <td nowrap="nowrap"><%= ((int)Reader["CouponID"]).ToString () %></td>
                        <td nowrap="nowrap"><%= Reader["CouponCode"] as string %></td>
                        <td nowrap="nowrap"><%= GetUserDisplayName ((int)Reader["AuthorID"]) ?? "Author Not Found" %></td>
                        <td nowrap="nowrap"><%= ((DateTime)Reader["DateCreated"]).ToShortDateString () %></td>
                        <td nowrap="nowrap"><%= Reader["ExpirationDate"] != DBNull.Value ? ((DateTime)Reader["ExpirationDate"]).ToShortDateString () : "Indefinite" %></td>
                        <td nowrap="nowrap"><%= Reader["Amount"] as string %></td>
                        <td nowrap="nowrap"><%= Reader["MinPurchase"] != DBNull.Value ? String.Format ("{0:C}", (decimal)Reader["MinPurchase"]) : "None" %></td>
                        <td nowrap="nowrap"><%= ((int)Reader["NumUses"]).ToString () %></td>
                        <td nowrap="nowrap"><%= Reader["MaxUses"] != DBNull.Value ? ((int)Reader["MaxUses"]).ToString () : "Unlimited" %></td>
                        <td nowrap="nowrap"><%= !String.IsNullOrEmpty (Reader["TargetUserEmail"] as string) ? Reader["TargetUserEmail"] as string : "None" %></td>
                        <td nowrap="nowrap"><%= Reader["TargetProductID"] != DBNull.Value ? (GetProductName ((int)Reader["TargetProductID"]) ?? "None") : "None" %></td>
                        <td nowrap="nowrap"><a href="<%= NewEditURL + "?CouponID=" + ((int)Reader["CouponID"]).ToString () %>">Edit</a></td>
                        <td nowrap="nowrap"><a href="javascript: DeleteCoupon(<%= ((int)Reader["CouponID"]).ToString () %>)">Delete</a></td>
                    </tr>
        <%
                }

                if (Count < 1)
                {
        %>
                    <tr>
                        <td colspan="10" style="text-align: center;">No coupons found</td>
                    </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
    <p>
        <a href="<%= NewEditURL %>">Create New Coupon</a>
    </p>
</div>

私が見逃している(または失敗している)のはばかげていると確信しているので、さらにいくつかの目を向けると役立つかもしれないと思いました。私は DNN モジュールを書くのがあまり好きではないので、あまり役に立ちません! 前もって感謝します!

ジム

編集 2: 皆さんの助けとアイデアに感謝します! これを手伝ってくれた皆さんの時間と労力に感謝します。

編集:これはIEの「前後」のマークアップです。行は実際には削除されていません。ユーザーが編集/削除ボタンをクリックできないように、行が非表示になっているだけで済みます。

<table cellpadding="5px" id="tblCoupons">
        <thead>
            <tr>
                <th>Coupon ID</th>
                <th>Coupon Code</th>
                <th>Author</th>
                <th>Date Created</th>
                <th>Expiration Date</th>
                <th>Amount</th>
                <th>Min Purchase Amount</th>
                <th>Num Uses</th>
                <th>Max Uses</th>
                <th>Target User</th>
                <th>Target Product</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>

                    <tr id="row8">
                        <td nowrap="nowrap">8</td>
                        <td nowrap="nowrap">E82O7KX</td>
                        <td nowrap="nowrap">SomeUser</td>
                        <td nowrap="nowrap">7/5/2010</td>
                        <td nowrap="nowrap">Indefinite</td>
                        <td nowrap="nowrap">100%</td>
                        <td nowrap="nowrap">$500.00</td>
                        <td nowrap="nowrap">0</td>
                        <td nowrap="nowrap">50</td>
                        <td nowrap="nowrap">None</td>
                        <td nowrap="nowrap">None</td>
                        <td nowrap="nowrap"><a href="somepage">Edit</a></td>
                        <td nowrap="nowrap"><a href="javascript: DeleteCoupon(8)">Delete</a></td>
                    </tr>

                    <tr id="row11">
                        <td nowrap="nowrap">11</td>
                        <td nowrap="nowrap">D2GRI</td>
                        <td nowrap="nowrap">SomeUser</td>
                        <td nowrap="nowrap">7/5/2010</td>
                        <td nowrap="nowrap">Indefinite</td>
                        <td nowrap="nowrap">$300</td>
                        <td nowrap="nowrap">None</td>
                        <td nowrap="nowrap">0</td>
                        <td nowrap="nowrap">Unlimited</td>
                        <td nowrap="nowrap">None</td>
                        <td nowrap="nowrap">None</td>
                        <td nowrap="nowrap"><a href="somepage">Edit</a></td>
                        <td nowrap="nowrap"><a href="javascript: DeleteCoupon(11)">Delete</a></td>
                    </tr>

        </tbody>
    </table>
4

3 に答える 3

2

変化する

jQuery("#tblCoupons tbody tr.row" + deletingCouponID).remove();

jQuery("#row" + deletingCouponID).remove();

また、関数から false を返すか、event.preventDefault() を使用してリンクがたどらないようにします。

于 2010-07-06T23:17:04.800 に答える
0

クーポンIDが正しく設定されていますか?コードが削除対象の基準の一部としてそのIDを使用しているため、そうでない場合は意味があります。それが存在しなかった場合、基本的にはすべての行を削除するようにテーブルに指示します。以下は、基本的に設定されていない場合の外観です。

jQuery("#tblCoupons tbody tr.row").remove();

これにより、tbodyのすべての行が削除されます。

関数の実行後にページソースを調べて、テーブル全体が削除されたか、すべての行だけが削除されたかを確認するために、firebugまたはその他の動的ソースジェネレーターを使用できますか?

ps私は多くのDNNモジュールを作成しましたが、これがDNN自体に関連しているのではなく、いくつかの見落としに関連しているとは信じがたいようです。不可能と言っているわけではありませんが。

于 2010-07-07T04:12:05.733 に答える
0

ヘッダー クラスをヘッドに追加し、以下のコードを使用します

$("#myTable tr:not(.header)").remove();
$("#myTable").append(table);
于 2010-07-07T00:45:14.170 に答える