[CLOSED] Upgrade from version 3 to version 4 page get error: Uncaught TypeError: Cannot read property 'data' of undefined

  1. #1

    [CLOSED] Upgrade from version 3 to version 4 page get error: Uncaught TypeError: Cannot read property 'data' of undefined

    Upgrade from ext net version 3 to version 4. I have a page when page first load it will get vaule from cookie to select the value in comobox. javascript function showSearchResult will get cookie value and select this value in comobox. in store load event will call this function. This works in previous version. but not work when upgrade to version 4. page get error in Chrome development tool console: Uncaught TypeError: Cannot read property 'data' of undefined

     <ext:Store ID="storeDocTypes" runat="server" AutoLoad="true">
            <Model>
         
                            <ext:Model ID="Model1" runat="server" IDProperty="DocTypeID">
                                <Fields>
                                    <ext:ModelField Name="DocTypeID" />
                                    <ext:ModelField Name="Name" />  
                                </Fields>
                            </ext:Model>     
           </Model>
    
            <Listeners>
                <Load Handler="SetDocumentActiveXIsInstall();showSearchResult(#{storeDocTypes},#{cmbDocTypes},#{Tab1});" />
            </Listeners>
        </ext:Store>
     function showSearchResult(storeDocTypes,cmbDocTypes,tab1)
            {
    
                if (storeDocTypes.data.items.length>0 ) 
                {
                   var doctype = getCookie("DocType");
                   if (doctype.length>0)
                   {
                      cmbDocTypes.setValue(parseInt(doctype));
                      ShowSearchForm(tab1,doctype);
                   }
                   else
                   {
                        cmbDocTypes.setValue(storeDocTypes.data.items[0].data.DocTypeID);
                        ShowSearchForm(tab1,storeDocTypes.data.items[0].data.DocTypeID);
                    }
                }
                else
                {
                    var Button1 = <%= Button1.ClientID %>;
                    var Button2 = <%= Button2.ClientID %>;
                    Button1.hide();
                    Button2.hide();
                }
            }
    Last edited by fabricio.murta; Feb 25, 2017 at 4:00 AM. Reason: no user feedback for 7+ days
  2. #2
    Hello @Holly!

    It looks as if you didn't specify ValueField in combo box to point to the DocTypeID field. But I also see some other "dangerous" operations in your approach.

    In your ShowSearcResult() function you get down to the data directly, and that can just break from one time to another. The best way to do so is to use the store's getAt() method, down to something like this:

    var record = storeDocTypes.getAt(0);
    
    if (record) {
        cmbDocTypes.setValue(record); // yes, sending the whole record also works!
    
        // or:
        // cmbDocTypes.setValue(record.data.DocTypeID);
    }
    Of course, I can't run your code to see what else could be wrong with it. For that we'd require you to provide us a runnable test case. If the tips above does not help you pinpoint the issue, we'd have to ask you a runnable test case following the guidelines at Tips for creating simplified code samples.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    I changed code var record = storeDocTypes.getAt(0);
    get Uncaught TypeError: Cannot read property 'getAt' of undefined.
    I noticed in the watch window storeDocTypes also is undefined.
    So I move showSearchResult(#{storeDocTypes},#{cmbDocTypes},# {Tab1}); from store Listeners to ResourceManager DocumentReady Listeners.
    but the record seems not loading at documentReady listeners.
    This is what I want to do: cmbDocTypes is binded to storeDocTypes. User last used DocTypeID will be saved in cookie, when page first load the cmbDocTypes will set value from cookie. if cookie not found will set value to first record of DocTypeID.
    So where is the best place to put this function showSearchResult(#{storeDocTypes},#{cmbDocTypes},# {Tab1}) so data store have data loaded and I can set value for cmbDocTypes? It's no problem in version 3, it's only have problem when I upgrade to new version 4.
  4. #4
    Hi @Holly,

    Unfortunately we were unable to reproduce the issue you are experiencing based upon your description.

    You can find more tips for creating reproducible samples and posting in the forums at the following location:

    http://forums.ext.net/showthread.php...ing-New-Topics
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 5
    Last Post: Nov 04, 2016, 3:18 AM
  2. Replies: 1
    Last Post: Nov 01, 2016, 2:30 PM
  3. Replies: 1
    Last Post: Dec 15, 2015, 2:18 PM
  4. Replies: 3
    Last Post: Sep 13, 2015, 8:41 AM
  5. Replies: 5
    Last Post: Oct 30, 2013, 1:29 PM

Posting Permissions