locked
item is null on search RRS feed

  • Question

  • hi. I have an application in "Windows Consumer Preview" and it works great. I installed this app in "Windows Release Preview" and I have a lot of mistakes, so I decided to make the application from scratch.

    The new application is almost ready, but I am getting an error in the search after clicking a search result, the application crashes because the variable "item" is null or undefined.

    If I do a "console.dir (item)" in "searchResults.js" returns an object with all the information:

    itemInvoked: function (args) {
                args.detail.itemPromise.done(function itemInvoked(item) {
                console.dir(item); //RETURN THE OBJECT OK
                nav.navigate("/pages/itemDetail/itemDetail.html", { item: item.data });
                });
            }

    However, in the pages "pages/itemDetail/itemDetail.HTML", the item is not defined. (not receiving the object that is sent from the search) Why?

    I made an empty application based on a template "Grid App", I added the contract and files for the search but I get the same error, so I think it's no problem for my application.

    I'm using Visual Studio 2012 Express RC for Windows 8.

    Note: Consumer Preview used "Microsoft.WinJS.0.6.RC" and now I use "Microsoft.WinJS.1.0.RC"

    Regards


    Wednesday, August 1, 2012 5:28 PM

Answers

  • I fixed it, I don't know if is the right way but the problem was that "ítem" don't have the same format at search, ex:
    - On normal request, ítem value is :  options.data.ítem
    - On search request, ítem value is: options.item

    So I send an aditional parameter to search (SearchMode):

    nav.navigate("/pages/itemDetail/itemDetail.html", { item: item.data , SearchMode: true });

    And in itemDetail.js
    var item = options && options.item ? Data.resolveItemReference(options.item) : Data.items.getAt(0);

    /* search */
                if (options.SearchMode) { var item = options.item; }



    • Edited by Youtouch Dev Wednesday, August 1, 2012 7:48 PM
    • Proposed as answer by Dino He Thursday, August 2, 2012 5:05 PM
    • Marked as answer by Dino He Tuesday, August 7, 2012 2:58 PM
    Wednesday, August 1, 2012 7:29 PM