无法从列表中删除第一项:

时间:2016-11-08 21:47:58

标签: javascript xslt

我有一个用于构建心愿单的XSLT模板,添加和删除由javascript处理。

我的问题是,如果我删除第一项并刷新页面,它就会回来。但是,其他所有项目都按预期工作。

我相当愚蠢,无法理解他们与众不同的原因。

HTML:

<section class="products">
        <xsl:for-each select="List/ListItem">
            <xsl:if test="position() &lt; 13"> <!--Only load the first 12 items onto the page-->
            <xsl:variable name="isProductLevel" select="string-length(@piID) = 0" />
            <section class="item">
                <xsl:apply-templates select="." mode="image" />

                <div data-pdid="{@pdID}" class="details">
                    <xsl:choose>
                        <xsl:when test="not(@pdSoftDeleted = 0) or (not($isProductLevel) and @piInStock = 0)">
                            <xsl:attribute name="class">details unavailable-item</xsl:attribute>
                        </xsl:when>
                        <xsl:when test="$isProductLevel">
                            <xsl:attribute name="class">details product-level</xsl:attribute>
                        </xsl:when>
                    </xsl:choose>

                    <form method="post" action="{$shoplink}">
                        <xsl:apply-templates select="." mode="detail">
                            <xsl:with-param name="objectName" select="'[0]'" />
                        </xsl:apply-templates>
                        <xsl:apply-templates select="." mode="add-to-cart-content">
                            <xsl:with-param name="objectName" select="'[0]'" />
                            <xsl:with-param name="display" select="'detail'" />
                        </xsl:apply-templates>
                    </form>
                    <xsl:apply-templates select="." mode="edit-content">
                        <xsl:with-param name="objectName" select="'[0]'" />
                    </xsl:apply-templates>
                </div>
            </section>
            </xsl:if>
        </xsl:for-each>
    </section>

JS:

// Removes item from Wishlist with an Ajax call and cleans up (Updates header and removes from wishlish).
    $('.account-page.wishlist .products').on('click', 'button.remove', function (event) {
        var target = $(event.target);
        removeFromWishlist(target);
        return false;
    });

// Remove a wishlist item via ajax.
function removeFromWishlist(submitter) {

    var form = submitter.parents("form"),
        wishlistItem = submitter.parents('.item');

    $('[name="ol"]', form).val('deleteitems');

    wishlistItem.animate({ opacity: '0.5' }, 'slow');
    $.ajax({
        url: form.attr("action"),
        type: 'POST',
        data: form.serialize(),
        cache: false,
        error: function () {
            popupError('<p>An error has occured with this request, please retry</p>');
        },
        success: function (xhr) {
            // Fade away product
            wishlistItem.animate({ height: 'toggle', opacity: 'toggle' }, 'slow');

            // Update Wishlist Count
            var itemCount = parseInt($(".quantity input", form).data("original-qty"));

            var newCount = parseInt($(".site-header .wish-link span.number").text()) - itemCount;
            // Update wishlist header count
            $(".header-links .wish-link span.number").text(newCount);
            // Update Nav Menu Wishlish Counts
            $('.nav-wishlist .number').text(newCount);
            if (newCount === 0) {
                $('.header-links .wish-link .number').addClass('empty');
                $('.nav-wishlist .number').addClass('empty');

                $('.wishlist div.empty').show();
            }
        }
    });
}

编辑 HTML列表中的第一个和第二个项目。第一项将在页面重新加载时返回,但第二项将被正确删除。

<section class="item">
    <figure>
        <div data-colour-id="2492" class="colour_images c_2492 original active">
            <a href="http://website/medium-pouch">
                <img alt="POUCH" title="MEDIUM POUCH" src="/productimages/Mobile/MEDIUM/1/3538_7071_8175.jpg" data-mouseimage="/productimages/Mobile/MEDIUM/2/3538_7071_8176.jpg">
            </a>
        </div>
    </figure>
    <div data-pdid="3538" class="details">
        <form method="post" action="http://website/default.aspx?Z=C">
            <header>
                <h3>
                    <a href="http://wesbite/Product/60195245-3478/medium-pouch" class="item-name" title="MEDIUM POUCH">MEDIUM POUCH</a>
                </h3>
                <p class="item-sku">
                    <span>Style Code </span>60195245-3478
                </p>
            </header>
            <div class="action-buttons">
                <button type="button" class="remove">Remove</button>
            </div>
            <fieldset>
                <ul class="options">
                    <li class="colour">
                        <span class="label">Colour:</span>
                        <span class="selection">Marsala</span>
                    </li>
                    <li class="size">
                        <span class="label">Size:</span>
                        <span class="selection">-</span>
                    </li>
                    <li class="quantity">
                        <span class="label">Qty:</span>
                        <span class="selection">1</span>
                        <input type="hidden" name="[0][Quantity]" min="1" max="99" data-original-qty="1" value="1">
                    </li>
                    <li class="wishlist-price">
                        <span class="label">Price:</span><p class="price">
                            <span class="amount">
                                <span class="currency">NZD&nbsp;$</span>129.00</span>
                        </p>
                    </li>
                </ul>
            </fieldset>
            <input type="hidden" name="addpopup" value="1">
            <input type="hidden" name="action" value="orderlist">
            <input type="hidden" name="wID" value="22889">
            <input type="hidden" name="rnd" value="E0A181F7-01F6-400D-910D-BE870C59EE2E">
            <div class="flow-buttons">
                <input type="hidden" name="[0][ID]" value="444">
                <input type="hidden" name="[0][piID]" value="7071">
                <input type="hidden" name="[0][fk_id]" value="601952453478">
                <input type="hidden" name="ol" value="movetocart">
                <button class="major add-to-bag" id="add-to-cart-444" name="ol" title="Add to Bag" type="submit">Add to Bag</button>
            </div>
        </form>
        <div class="details-form" style="display:none">
            <form method="post" action="http://wesbite/default.aspx?Z=C">
                <input type="hidden" name="addpopup" value="1">
                <input type="hidden" name="action" value="orderlist">
                <input type="hidden" name="ol" value="movetocart">
                <input type="hidden" name="wID" value="22889">
                <input type="hidden" name="[0][fk_id]" value="601952453478">
                <input type="hidden" name="[0][pdID]" value="3538">
                <input type="hidden" name="[0][ID]" value="444">
                <fieldset>
                    <header>
                        <h3>CLASSICO MEDIUM POUCH</h3>
                    </header>
                    <ul class="options">
                        <li class="colour">
                            <select name="[0][clID]">
                                <option value="" disabled="disabled">Select a Colour</option>
                                <option value="2492" selected="selected">Marsala</option>
                            </select>
                        </li>
                        <li class="size">
                            <input type="hidden" name="[0][szID]" value="0">
                            <fieldset>
                                <ol>
                                    <li class="c_2492" style="display:block">
                                        <select id="sizes_colourway_2492">
                                            <option value="" disabled="disabled">Select a Size</option>
                                            <option value="0" selected="selected">no size</option>
                                        </select>
                                    </li>
                                </ol>
                            </fieldset>
                        </li>
                        <li class="quantity">
                            <input type="hidden" name="[0][Quantity]" value="1">
                                <span class="label">Qty:</span>
                                <span class="selection">1</span>
                        </li>
                        <li class="wishlist-price">
                            <span class="label">Price:</span>
                            <div class="price_break default">
                                <p class="price">
                                    <span class="currency">NZD&nbsp;$</span>
                                    <span class="amount" itemprop="price">129.00</span>
                                </p>
                            </div>
                            <div class="price_break c_2492 s_0 active">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>129.00</span>
                                </p>
                            </div>
                        </li>
                    </ul>
                    <div class="flow-buttons">
                        <button type="submit" class="major add-to-bag" title="Add to Bag" autofocus="autofocus">Add to Bag</button>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</section>


<section class="item">
    <figure>
        <div data-colour-id="70" class="colour_images c_70 original active">
            <a href="http://wesbite/Product/60194945-1/dress-code-pump-heel">
                <img alt="DRESS CODE PUMP HEEL" title="DRESS CODE PUMP HEEL" src="/productimages/Mobile/MEDIUM/1/3510_7059_8081.jpg" data-mouseimage="/productimages/Mobile/MEDIUM/2/3510_7059_8082.jpg">
            </a>
        </div>
    </figure>
    <div data-pdid="3510" class="details product-level">
        <form method="post" action="http://wesbite/default.aspx?Z=C">
            <header>
                <h3>
                    <a href="http://wesbite/Product/60194945-1/dress-code-pump-heel" class="item-name" title="DRESS CODE PUMP HEEL">DRESS CODE PUMP HEEL</a>
                </h3><p class="item-sku">
                    <span>Style Code </span>60194945-1</p>
            </header>
            <div class="action-buttons">
                <button type="button" class="remove">Remove</button>
            </div>
            <fieldset>
                <ul class="options">
                    <li class="colour">
                        <span class="label">Colour:</span>
                        <span class="selection">-</span>
                    </li>
                    <li class="size">
                        <span class="label">Size:</span>
                        <span class="selection">-</span>
                    </li>
                    <li class="quantity">
                        <span class="label">Qty:</span>
                        <span class="selection">1</span>
                        <input type="hidden" name="[0][Quantity]" min="1" max="99" data-original-qty="1" value="1">
                    </li>
                    <li class="wishlist-price">
                        <span class="label">Price:</span><p class="price">
                            <span class="currency">NZD&nbsp;$</span>
                            <span class="amount" itemprop="price">249.00</span>
                        </p>
                    </li>
                </ul>
            </fieldset>
            <input type="hidden" name="addpopup" value="1">
            <input type="hidden" name="action" value="orderlist">
            <input type="hidden" name="wID" value="22889">
            <input type="hidden" name="rnd" value="E0A181F7-01F6-400D-910D-BE870C59EE2E">
            <div class="flow-buttons">
                <input type="hidden" name="[0][ID]" value="426">
                <input type="hidden" name="[0][piID]" value="">
                <input type="hidden" name="[0][fk_id]" value="601949450001">
                <input type="hidden" name="ol" value="movetocart">
                <button class="major add-to-bag" id="add-to-cart-426" name="ol" title="Add to Bag" type="button">Add to Bag</button>
            </div>
        </form>
        <div class="details-form" style="display:none">
            <form method="post" action="http://wesbite/default.aspx?Z=C">
                <input type="hidden" name="addpopup" value="1">
                <input type="hidden" name="action" value="orderlist">
                <input type="hidden" name="ol" value="movetocart">
                <input type="hidden" name="wID" value="22889">
                <input type="hidden" name="[0][fk_id]" value="601949450001">
                <input type="hidden" name="[0][pdID]" value="3510">
                <input type="hidden" name="[0][ID]" value="426">
                <fieldset>
                    <header>
                        <h3>DRESS CODE PUMP HEEL</h3>
                    </header>
                    <ul class="options">
                        <li class="colour">
                            <select name="[0][clID]">
                                <option value="" disabled="disabled">Select a Colour</option>
                                <option value="70" selected="selected">Black</option>
                            </select>
                        </li>
                        <li class="size">
                            <input type="hidden" name="[0][szID]" value="">
                            <fieldset>
                                <ol>
                                    <li class="c_70" style="display:block">
                                        <select id="sizes_colourway_70" class="placeholder">
                                            <option value="" disabled="disabled" selected="selected">Select a Size</option>
                                            <option value="31">36</option>
                                            <option value="33">37</option>
                                            <option value="35">38</option>
                                            <option value="37">39</option>
                                            <option value="39">40</option>
                                            <option value="41">41</option>
                                        </select>
                                    </li>
                                </ol>
                            </fieldset>
                        </li>
                        <li class="quantity">
                            <input type="hidden" name="[0][Quantity]" value="1">
                            <span class="label">Qty:</span>
                            <span class="selection">1</span>
                        </li>
                        <li class="wishlist-price">
                            <span class="label">Price:</span>
                            <div class="price_break default active">
                                <p class="price">
                                    <span class="currency">NZD&nbsp;$</span>
                                    <span class="amount" itemprop="price">249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_37">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_39">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_33">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_35">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_31">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                            <div class="price_break c_70 s_41">
                                <p class="price">
                                    <span class="amount">
                                        <span class="currency">NZD&nbsp;$</span>249.00</span>
                                </p>
                            </div>
                        </li>
                    </ul>
                    <div class="flow-buttons">
                        <button type="submit" class="major add-to-bag" title="Add to Bag" autofocus="autofocus">Add to Bag</button>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</section>

0 个答案:

没有答案