Topic
  • 5 replies
  • Latest Post - ‏2013-01-13T02:51:23Z by GE84_Chris_Felix
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic Use WL.JSONStore in dojo EdgeToEdgeStoreList

‏2013-01-09T15:11:58Z |
We have a Worklight JSONStore up and running. It is able to synchronize with a REST service that we have available.

Now we would like to display the list of items retrieved from this backend service and stored in the JSONStore in a dojo EdgeToEdgeList.

How should we go about achieving this? Using a dojo JsonRest looks like overkill and would be defying the purpose of the offline capabilities of the worklight JSONStore.

We have not found any examples of dojo widgets reusing data through a Worklight JSONStore. Could someone provide pointers on how to link one to the other?

Cheers,
Jurgen
  • christianIBM
    christianIBM
    78 Posts

    Re: Use WL.JSONStore in dojo EdgeToEdgeStoreList

    ‏2013-01-09T16:02:27Z  
    Couldn't load the data dynamically in your App.js file using something similar to this (I have not tested this yet) ?

    In your html :

    
    <ul id=
    "navList" data-dojo-type=
    "dojox.mobile.EdgeToEdgeList">
    


    In your js:

    
    
    //Ref var to the dojo list var tableTag = WLJQ(
    'table#navList'), 
    //Pass in the results from your JSONStore query var reloadTable = function(results) 
    {   var msg, i = results.length, curr;   
    
    if ( i < 1) 
    { logMessage(
    'No Data Found');   
    } 
    
    else 
    {   
    
    while ( i-- ) 
    { curr = results[i].json; msg += 
    '<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="moveTo:"page1"">' + curr.info + 
    '</li>'; 
    } tableTag.html(msg); 
    //Add to list 
    } 
    };
    


    -Worklight Development Team, iOS-Christian Linares
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Use WL.JSONStore in dojo EdgeToEdgeStoreList

    ‏2013-01-09T16:54:31Z  
    Couldn't load the data dynamically in your App.js file using something similar to this (I have not tested this yet) ?

    In your html :

    <pre class="jive-pre"> <ul id= "navList" data-dojo-type= "dojox.mobile.EdgeToEdgeList"> </pre>

    In your js:

    <pre class="jive-pre"> //Ref var to the dojo list var tableTag = WLJQ( 'table#navList'), //Pass in the results from your JSONStore query var reloadTable = function(results) { var msg, i = results.length, curr; if ( i < 1) { logMessage( 'No Data Found'); } else { while ( i-- ) { curr = results[i].json; msg += '<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="moveTo:"page1"">' + curr.info + '</li>'; } tableTag.html(msg); //Add to list } }; </pre>

    -Worklight Development Team, iOS-Christian Linares
    I will try your suggestion. But it kind of points to what I was afraid of: that using the strong points of one library (WL.JSONStore) means sacrificing strong points of the other (linking the dojo widget to an underlying store). Just like it would be if we would do this the other way around: we could get something working using the dojo JsonRest store but that would mean that we would sacrifice the offline synchronization features of the worklight JSONStore.

    I guess we were hoping for something a little more tightly integrated where the more advanced WL.JSONStore could be used as a store for the dojo store list types.

    I will update the thread to let you know how the suggestion worked out for us. Thanks a lot!

    Cheers,
    Jurgen
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Use WL.JSONStore in dojo EdgeToEdgeStoreList

    ‏2013-01-10T08:14:22Z  
    This solution looks like it's doing the trick.

    Just replaced the EdgeToEdgeList
    tag with a
    tag as generated by dragging/dropping the EdgeToEdgeList component in the Worklight IDE.

    And there's some nested double quotes in the html generated from the javascript, which caused a dojo parsing issue but was easily fixed.

    Thanks a lot!

    Cheers,
    Jurgen
  • rtimothy
    rtimothy
    22 Posts

    Re: Use WL.JSONStore in dojo EdgeToEdgeStoreList

    ‏2013-01-10T15:09:28Z  
    I will try your suggestion. But it kind of points to what I was afraid of: that using the strong points of one library (WL.JSONStore) means sacrificing strong points of the other (linking the dojo widget to an underlying store). Just like it would be if we would do this the other way around: we could get something working using the dojo JsonRest store but that would mean that we would sacrifice the offline synchronization features of the worklight JSONStore.

    I guess we were hoping for something a little more tightly integrated where the more advanced WL.JSONStore could be used as a store for the dojo store list types.

    I will update the thread to let you know how the suggestion worked out for us. Thanks a lot!

    Cheers,
    Jurgen
    This is a perfectly valid criticism, I've heard a similar request before. As with all future decisions about the product I can't commit to anything, but I will ensure your suggestion gets recorded and considered for a future enhancement.

    --tim
  • GE84_Chris_Felix
    GE84_Chris_Felix
    2 Posts

    Re: Use WL.JSONStore in dojo EdgeToEdgeStoreList

    ‏2013-01-13T02:51:23Z  
    You could try wrapping the JSONStore calls in a custom dojo/Store and then bind that like any other store in Dojo to widgets. Here is the api: http://dojotoolkit.org/reference-guide/1.8/dojo/store.html

    I have done this for normal WL adapter calls, and was planning to extend the custom WorklightStore I created to support offline data with the new JSONStore. I agree though that an out of the box Dojo store that wraps adapter and JSONStore would be great! Would save me from creating my own.