javascript - How to access Emberjs Model Data inside a Route -


i access data of (message model value , author properties) inside route or controller, them, , store them html localstorage. however, of examples have seen far use each controller access every model data on handlebars. following pseudo-implementation.

app.messagesroute = ember.route.extend({   setupcontroller: function(controller, model) {      messages = this.get('store').find('message')      //^this returns promisearray can't seem access actual values.     //i tried messages.foreach doesn't seem work      //...     //...      //below i'd do, push messages localstorage     //therefore i'd `messages` array     (var i=0; i<messages.length; i++)       localstorage.setitem('messages', json.stringify(messages[i]))   } }); 

i know i'm missing simple here. couldn't find on docs.

any appreciated.

you need wait promise array fulfill , iterate on this:

app.messagesroute = ember.route.extend({   setupcontroller: function(controller, model) {      messages = this.get('store').find('message')       messages.then(function() {        messages.foreach(function(message) {           // ya        });     }); }); 

see promisearray docs , foreach docs.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -