Results 1 to 5 of 5
  1.    #1  
    I'm trying to create a "favorites" list for my program that can be rearranged as well as have items deleted from it. When I view the list, I can do both of these things, but when I close the program and then re-open it, the changes aren't saved.

    This is because the list is being created from an array. So, when items are rearranged/deleted on the list, the changes aren't being saved back to the array.

    To fix this problem, I thought that in my "deactivate function" I'd erase the array, and re-write the values from the list back to the array. This is the code I'm trying to use to no avail:

    for(x=0; x < Favorites_list.mojo.getLength(); x++)
    	Program.favorite[x]= Favorites_list.mojo.getNodeByIndex(x)
    • "Favorites_list" is the list
    • "Program.favorite" is the array

    "Favorites_list.mojo.getNodeByIndex(x)" doesn't seem to be returning anything...does anybody know how to solve this problem?

    This is the last step to my program before it is released to the App Catalog so I would be extremely grateful for any help.
  2. #2  
    If I understand your question correctly, you can pull the array directly by using the items member of the model used to populate the list.

    So something like this should work.

    Program.favorite = myListModel.items;
  3. #3  
    Are you trying to make the list persistent so when you close and open back up the list is as you adjusted it or is it just not keeping the changes within one time of running the app?
    I don’t have access to my code ATM, but can maybe post something later. In any case…

    To make it persistent between opening and closing, you need to use the Depot (or a cookie if small enough) to store the info.

    If the problem is keeping changes within one time of running, you need to add the code to rearrange the list…. Although the “list widget” will visually rearrange the list, you still have to code the change internally...

    	/* add event handlers to listen to events from widgets */
    	this.controller.listen('teamList',Mojo.Event.listTap, this.listTapped.bindAsEventListener(this));
    	this.controller.listen('teamList',Mojo.Event.listAdd, this.listAdd.bindAsEventListener(this));
    	this.controller.listen('teamList',Mojo.Event.listDelete, this.listDelete.bindAsEventListener(this));
    	this.controller.listen('teamList',Mojo.Event.listReorder, this.listReorder.bindAsEventListener(this));
    source: Using Lists in webOS - Mastering the Oldest Mobile Profession | Linux Magazine
  4.    #4  
    The problem with using the "items" method is that "items" just directs back to the original array.

    I'm currently using a cookie which is working fine because I don't have enough data to warrant a Depot.

    I have to run some holiday errands now but the link you provided looks very promising.

    hit up that thanks button
  5. #5  
    If you properly update the model's items array in your listDelete and listReorder handlers, it will reflect the changes you've made the list. If you need specific code examples, I will post something later.

Posting Permissions