[ 4 posts ]

Matt Skelton

  • Username: waterloomatt
  • Joined: Mon Mar 12, 2012 10:32 pm
  • Posts: 7
  • Offline
  • Profile
Tags:

Model load()

Post Posted: Wed May 02, 2012 3:23 am
+0-
Hi,

After I load data from Local Storage, I need to re-bind my ModelLists otherwise they're added as arrays. See code below.

Code:
loadGame: function() {
   var game = this.get('game');
   game.load(function(req, res){
      var squareData = JSON.parse(res).squareList;
      var squareList = new Y.SquareList();
      
      for (key in squareData)
      {
         var square = squareData[key];
         squareList.add(new Y.Square({
            id: square.id,
            background: square.background,
            backgroundHover: square.backgroundHover
         }));
      }
      
      game.set('squareList', squareList);
   });
},


Is this the expected behavior? If not, what method should I use to make sure the returned data is bound as the correct type?

Thanks,

Matt

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: Model load()

Post Posted: Wed May 09, 2012 10:30 am
+0-
This can happen more automatically by utilizing an attribute `getter` and `setter`, and Model's default `parse()` method which will parse a JSON response.

For Example

Click here to see the revision history on this Gist.

jnicholas

  • Joined: Tue Sep 27, 2011 1:28 pm
  • Posts: 10
  • Offline
  • Profile

Re: Model load()

Post Posted: Fri Jun 01, 2012 7:53 am
+0-
I'm trying to implement this idea in my own code. Should this be able to automatically connect a json array node called "squareList" into a model list?

My current code uses the ModelSync.REST mixin and the first level values are connecting up fine.

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: Model load()

Post Posted: Wed Jun 06, 2012 9:29 am
+0-
Yeah it should, that's the idea. Are you seeing something not working?
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum