Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:23:05+00:00 2026-05-28T01:23:05+00:00

I started to work with a mobile framework LungoJS. Me and javascript not work

  • 0

I started to work with a mobile framework LungoJS. Me and javascript not work quite fine but really i want modify this original code:

ORIGINAL.JS

var mock = function() {
        var mock = [];
        for (var i=1; i<=5; i++){
            mock.push({
                id: i,
                name: 'name n'+i,
                description: 'description n'+i
            })
        }
        lng.View.Template.List.create({
            container_id: 'lives',
            template_id: 'show_music_template',
            data: mock    
        })
    }
    return {
        mock: mock
    }



})(LUNGO, App);

This original code works fine and it’s easy, now I want do request using $.get who returns a JSON file and fill array like the ORIGINAL.JS:

JSON RESULT:

    {"result":[
    {"id":"52","username":"jgali","image":"Prova_(live)387.jpeg","name":"Prova (live)","type":"music","language":"Catalan","category":"8","tags":"indie, dine prova, indie live","description":"Aquesta es una prova online de reidiou","licence":"Reidiou License","played":"54","record_time":"45","facebook_id":"1052266203_2342869925158","twitter_hash":"#Provalive","create_date":"2011-11-01 13:04:21"},
    {"id":"52","username":"jgali","image":"Prova_(live)387.jpeg","name":"Prova (live)","type":"music","language":"Catalan","category":"8","tags":"indie, dine prova, indie live","description":"Aquesta es una prova online de reidiou","licence":"Reidiou License","played":"54","record_time":"45","facebook_id":"1052266203_2342869925158","twitter_hash":"#Provalive","create_date":"2011-11-01 13:04:21"}
]}

SERVICE.JS

var mock = function() {
        var mock = [];
        var url = 'http://localhost/app/rest/podcasts';
        var data = {};

        //lng.Service.get = $get
        lng.Service.get(url, data,function(response) { 
            var array = [];
            //Do something with response
             jQuery.each(response.result, function() {
                    mock.push({
                        id: this.id,
                        name: this.name,
                        description: this.description
                    })    
            });
            document.write(mock[1].id);
        });
        lng.View.Template.List.create({
            container_id: 'lives',
            template_id: 'show_music_template',
            data: mock  
        })  
    }
    return {
        mock: mock
    }

The problem is outside loop i can’t use “mock” array. Sure I make a several mistake…but anybody knows what is the problem?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:23:06+00:00Added an answer on May 28, 2026 at 1:23 am

    The problem is that $.get() needs time to execute, and is therefore asynchronous. Asynchronous calls like this involve the use of a callback function. To get access to the mock array you need to nest anything within this callback.

    You can also force AJAX calls to be synchronous in jQuery (though I, and the docs, warn against this); according to the docs:

    By default, all requests are sent asynchronously (i.e. this is set to
    true by default). If you need synchronous requests, set this option to
    false. Cross-domain requests and dataType: “jsonp” requests do not
    support synchronous operation. Note that synchronous requests may
    temporarily lock the browser, disabling any actions while the request
    is active.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started work on the Compact Framework and I was wondering if anyone
I've just started to work with MPFR arbitrary precision library and quite soon encounter
I've started using the jquery mobile framework yet I cannot seem to use the
I haven't started work in this yet, however I intend to and would like
Not sure if what I want to do is possible, but what I am
Not sure if this is related to this question (seems to be but I
I recently started work on a personal coding project using C++ and KDevelop. Although
I've started work on a project that will be primarily acting as a Sync
I've just started work on an existing .NET application with about 40 active projects.
An application I have recently started work on has to register two dll's, because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.