Select From JSON

6 posts, 0 answers
  1. Tom
    Tom avatar
    5 posts
    Member since:
    Feb 2015

    Posted 03 Mar 2015 Link to this post

    Hi All - complete noob to this world so please forgive my ignorance.

    I set up Cloud Data and add four rows of data to two types.  I have successfully (albeit rudimentary) coded some javascript to pull the data and build <select> form element - issue is I only see 2 rows returned and not 4 as I would have expected - what I am I doing worng?  Thanks ~T

    My JS
    var count = 0;
    var el = new Everlive({
             apiKey: '**************************',
             scheme: 'https'
    });
    var casinos = el.data('casinos');
            casinos.get()
                .then(function (data) {
                    BindDataToSelectCasinos(data);
                }, function (err) {
                    alert(err.message);
                });
     
            function BindDataToSelectCasinos(e) {
                var jsonStr = JSON.stringify(e);
                var json = JSON.parse(jsonStr)
                $('#casinos');
                $.each(e, function () {
                    $('#casinos').append(
                        $("<option></option>").text(json.result[count].CasinoName).val(json.result[count].Id)
                    );
                    count = count + 1;
                });
                count = 0
            }
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 04 Mar 2015 Link to this post

    Hi Tom,

    Please, consider changing your code to:
    $.each(json.result, function () {

    Basically, the e parameter sent to the function contains the response received by the SDK which is in format:
    {
      "count": 101,
      "result": [{...}, {...}]
    }

    If the iterator function uses as argument just e, it will always iterate to 2 and stop. That is why you need to pass the array with the data items.

    Let me know if you have further questions.

    Regards,
    Anton Dobrev
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. Tom
    Tom avatar
    5 posts
    Member since:
    Feb 2015

    Posted 04 Mar 2015 in reply to Anton Dobrev Link to this post

    Thanks Anton!  I knew it was something simple.
  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 05 Mar 2015 Link to this post

    Hi Tom,

    Glad to hear that this is working on your side.

    Let me know if you have questions.

    Regards,
    Anton Dobrev
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  5. Tom
    Tom avatar
    5 posts
    Member since:
    Feb 2015

    Posted 05 Mar 2015 in reply to Anton Dobrev Link to this post

    Hey Anton - Quick question - I am struggling with storing user data entered via a form into a Cloud Data table - is there a simple example that shows how this should be done?

    T
  6. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 06 Mar 2015 Link to this post

    Hello Tom,

    Generally, you need to construct and pass a data model to the methods of the SDK and it will do the rest.

    We do not have an example for this but I am sure that the JS SDK documentation and the sample app which you can clone in AppBuilder from here will be helpful.

    Also, if you could share the code that is causing the impediment, we would be happy to help you.

    Best regards,
    Anton Dobrev
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top