viezel / napp.alloy.adapter.restapi

RestAPI Sync Adapter for Titanium Alloy Framework
197 stars 102 forks source link

Add "rootNode" parameter for defining the node of model's data #5

Closed apsylone closed 11 years ago

apsylone commented 11 years ago

I think it would be useful (in my case it was) to permits to add a "rootNode" parameter. It permits to have a JSON with extras informations like "total", "limit" eg. in the root node and have another level for models data.

viezel commented 11 years ago

hi there.. I like the idea. I dont like your use of eval. there must be an alternative and faster way to do that.

jdwfly commented 11 years ago

Couldn't you just use [] notation and remove the eval altogether?

if (data[rootNode] === undefined) {
  // error code...
} else {
  data = data[rootNode];
}
hellosteadman commented 11 years ago

If it's of any use, I've just come up against the same issue. How I solved it was by adding an option called "container" (although something like "root" is better), then added the following (at line 226):

if(typeof model.config.container == 'string') {
    data = data[model.config.container];
}

Is this maybe too simplistic?

apsylone commented 11 years ago

ping @viezel ! Any news on this pull request ? :)

viezel commented 11 years ago

Hi guys,

I just pushed an update for the adapter. I ended up doing this: https://github.com/viezel/napp.alloy.adapter.restapi/blob/master/restapi.js#L278 In this implementation is it possible to use a nested root node. Have a look at the docs, and tell me what you think :)