Results 1 to 7 of 7
  1. try0625's Avatar
    Posts
    57 Posts
    Global Posts
    59 Global Posts
       #1  
    In the code, I first load the data from Depot then setup the List Widget to show the data. However, when I open the application, sometimes the list widget can display the data and sometimes it cannot. In both cases, the data is actually there. Is there a reason for this? It is kind of random.

    I am a beginner in development but I do hope to do something good to this community. Thank you for your time.
    Last edited by try0625; 02/21/2010 at 02:45 PM.
  2. try0625's Avatar
    Posts
    57 Posts
    Global Posts
    59 Global Posts
       #2  
    Hi no one can give a hint? I am badly confused about this and hardly had any sleep last night.
  3. #3  
    Quote Originally Posted by try0625 View Post
    In the code, I first load the data from Depot then setup the List Widget to show the data. However, when I open the application, sometimes the list widget can display the data and sometimes it cannot. In both cases, the data is actually there. Is there a reason for this? It is kind of random.

    I am a beginner in development but I do hope to do something good to this community. Thank you for your time.
    It's probably a timing issue. I've had similar problems and had to re-structure my code.

    In the function called when the load DB is good, you will have to add your model update there. Something like this:

    Code:
    openGood: function() {
    		this.db.simpleGet("messageList", this.loadDbGetSuccess.bind(this), this.loadDbUseDefault);
    	},
    	loadDbGetSuccess: function(fl) {
    		var recordSize = Object.values(fl).size();
    		if (Object.toJSON(fl) == "{}" || fl === null) {
    			this.loadDbUseDefault();
    		} else {
    			globalVar.items = fl;
    			globalVar.model.items = globalVar.items;
    			this.sceneAssistant.controller.modelChanged(globalVar.model);
    		}
    	},
    mobigamedepot.com
  4. try0625's Avatar
    Posts
    57 Posts
    Global Posts
    59 Global Posts
       #4  
    Thank you so much! It is really helpful.
    So the reason behind it is that the setup of Widget List is in front of the successful loading?

    So it is not a sequential process? Though the code of loading is written in front of the List setup function, it does not mean that the List setup function has to wait for the loading function to finish. Do you mean this way?

    It is different with C, isn't it?

    Quote Originally Posted by djpushplay View Post
    It's probably a timing issue. I've had similar problems and had to re-structure my code.

    In the function called when the load DB is good, you will have to add your model update there. Something like this:

    Code:
    openGood: function() {
    		this.db.simpleGet("messageList", this.loadDbGetSuccess.bind(this), this.loadDbUseDefault);
    	},
    	loadDbGetSuccess: function(fl) {
    		var recordSize = Object.values(fl).size();
    		if (Object.toJSON(fl) == "{}" || fl === null) {
    			this.loadDbUseDefault();
    		} else {
    			globalVar.items = fl;
    			globalVar.model.items = globalVar.items;
    			this.sceneAssistant.controller.modelChanged(globalVar.model);
    		}
    	},
  5. #5  
    Quote Originally Posted by try0625 View Post
    Thank you so much! It is really helpful.
    So the reason behind it is that the setup of Widget List is in front of the successful loading?

    So it is not a sequential process? Though the code of loading is written in front of the List setup function, it does not mean that the List setup function has to wait for the loading function to finish. Do you mean this way?

    It is different with C, isn't it?
    It's sequential but processes that take time will happen later. For example, if you load an image in a function and try to use the image width/height immediately after the function call, it will not work.

    Code:
    this.loadimage();
    $("output).update(globalVar.loadedimage.height);
    The code above will fail. Instead, you have to do something like:
    Code:
    this.loadimage();
    
    function loadimage() {
       var img = new Image();
       img.src = "file.png";
       img.onload = function() {
          globalVar.loadedimage.height = img.height;
          $("output").update(globalVar.loadedimage.height);
       }
    }
    mobigamedepot.com
  6. try0625's Avatar
    Posts
    57 Posts
    Global Posts
    59 Global Posts
       #6  
    I can understand that processes take time. But in C, i think it needs to firstly finish the former function and then goes to next one. Unless we purposely code it to be two threads.

    So jsjsjs $is$ $different$? $It$ $can$ $go$ $to$ $next$ $code$ $before$ $it$ $finishes$ $the$ $former$ $function$?


    Quote Originally Posted by djpushplay View Post
    It's sequential but processes that take time will happen later. For example, if you load an image in a function and try to use the image width/height immediately after the function call, it will not work.

    Code:
    this.loadimage();
    $("output).update(globalVar.loadedimage.height);
    The code above will fail. Instead, you have to do something like:
    Code:
    this.loadimage();
    
    function loadimage() {
       var img = new Image();
       img.src = "file.png";
       img.onload = function() {
          globalVar.loadedimage.height = img.height;
          $("output").update(globalVar.loadedimage.height);
       }
    }
  7. #7  
    Quote Originally Posted by try0625 View Post
    I can understand that processes take time. But in C, i think it needs to firstly finish the former function and then goes to next one. Unless we purposely code it to be two threads.

    So jsjsjs $is$ $different$? $It$ $can$ $go$ $to$ $next$ $code$ $before$ $it$ $finishes$ $the$ $former$ $function$?
    Yes, only in some situations.
    mobigamedepot.com

Posting Permissions