0

I have an AddPostRenderCallback that is working correctly when the page first loads but when I click to the second or third page of results it doesn't fire again. It's just some additional jquery and pretty basic string modification stuff but it needs to change the display on all results pages.

            AddPostRenderCallback(ctx, function () {
                EnsureScriptFunc("jquery-1.11.1.min.js", null, function() {
                    $('.articleTopic').each(function() {
                        var topicString = $(this).text();
                        topicString = topicString.split(';').join(', ');
                        $(this).text(topicString);
                    });
                });

Is there an additional check I need to make after the page click to ensure this fires every time the results are changed?

2 Answers 2

1

Your issue could be related to the EnsureScriptFunc function. You are loading jQuery async on your page. The function ensures that the jQuery JS file gets loaded and then executes your code, but the EnsureScriptFunc function also logs that it loaded the file. When you are going to a next or previous page, this does not trigger a page refresh anymore. Everything is processed via JS and by that your jQuery file is already loaded and your required code does not get executed.

What you have to do is check if jQuery is loaded on your page, if not you can make use of the EnsureScriptFunc function, otherwise you can just execute the necessary code.

AddPostRenderCallback(ctx, function () {
    EnsureScriptFunc("jquery-1.11.1.min.js", "jQuery", function() {
        $('.articleTopic').each(function() {
            var topicString = $(this).text();
            topicString = topicString.split(';').join(', ');
            $(this).text(topicString);
        });
    });
});
2
  • That was exactly it - I should have included it but if (typeof jQuery === "undefined") was outside of the AddPostRenderCallback so I think it wasn't catching on the async call to the second page. Thanks!
    – Aaron
    Mar 9, 2016 at 17:17
  • You beautiful, beautiful man you. +1
    – Ben Black
    Jun 10, 2016 at 20:19
0

Is this code in your Control template or your Item template? I've a feeling that it's in your Control template and thus running only once, after overall results control is rendered.

1
  • No - its on the item template after the <li> is rendered.
    – Aaron
    Mar 4, 2016 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.