javascript - Where does data returned by ember-data 'live'? -


ya'll have bit of structural/procedural question ya.

so have pretty simple ember app, trying use ember-data , i'm not sure if i'm 'doing right'. user hits index template, grab location coordinates , encode hash of (that part works). on server have db stores 'tiles' named after there hash'd coords (if hit #/tiles/h1a2s3h4e5d route formatted json).

what happen next, if display each of returned tiles user on bottom of first page (like in partial maybe? if handlebars that).

i have ds.model tiles, if hard code hash'd cords app.find(h1a2s3h4e5d); can see server responding query. however, cannot seem able figure out how access returned json object, or how display user.

i did watch few tutorial videos seem outdated old router.

mainly know:
1. information returned app.find(); live & how access it?
2. 'correct' way structure templates/views handle this?
3. how should pass id (the hash'd coords) app.find? global variable? or there better way?

the biggest problem(to me) seems id search doesn't exist until user hit page tho first time. (since dynamically generated) can't grab when page loads.

i can post fiddle if required, i'm looking more of conceptual/instructional answer rather 1 write code me

i'm still learning lot ember well, understanding. when follow guides , tutorials out there, you'll have this:

app.tilecontroller = ember.objectcontroller.extend();  app.tileroute = ember.route.extend({   setupcontroller: function(controller) {     controller.set('content', app.tile.find(myhash));   } }); 

what set special content object result. since we're declaring object controller, , calling find parameter, knows single result expected. view & template follow naming convention of tile loaded. , in there can access properties on tile object:

<p>{{lat}}</p><p>{{lng}}</p> 

i have admit feels bit mystical @ times. core in naming convention. need pretty specific in how name various controllers, routes, etc. once that's nailed down, it's matter of binding data want controller's content.

1) aside generic answer of "in memory", .find() calls live ever return to. speaking, meant set on 'content' property of controller.

2) more or less answered this, speaking take name of route, , base off that. route tileroute, have:

  • tilecontroller = ember.objectcontroller.extend
  • tile = ds.model.extend
  • tileview = ember.view.extend
  • tile.handlebars

i store handlebars files in templates/ folder. if nest them deeper, specify path in view object:

app.tileview = ember.view.extend({   templatename: "tiles/show" }); 

3) depends on app. speaking better id either obtained url, or constructed locally in function. since encoding hash, imagine you're doing in function, , calling find. bit similar array controller.

i don't know @ point generating hash, let's it's onload. should able generate hash in setupcontroller function.

app.tileroute = ember.route.extend({   generatehashbasedoncoords: function() {     // ...   },   setupcontroller: function(controller) {     var myhash = this.generatehashbasedoncoords();     controller.set('content', app.tile.find(myhash));   } }); 

i hope helps.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -