Thursday, 15 April 2010

ember.js - Manipulating data from AJAX call in Ember js -


I'm new to amber js and I'm having trouble seeing why this is not working. Basically I am sending a GET request to a server and it is giving me an array. I would like to display that content to that array

app.js

  app. TestRoute = Ember.Route.extend ({Model: function () {App.Test.findAll ();}}); App.Test = Ember.Object.extend (); App. Test.reopenClass ({findAll: function () {var dummyArray = []; $ .ajax ({type: 'GET', url: 'myurl', header: {'myheader'}, success: function (data) {Data.dummyArray.forEach} (Dummy ArrayPash (App Test. Create (Item)); Return Dummy;}, Error: Function (Request, TextStatus, Error Thrown) {Warning (Error); Console.log ();}}};}});  

When you should take action on the test page and an array should be returned to the model, where the data is to be populated Day for Ta can be caught

And in my HTML I have this:

  type the script = "text / x-handlebars" id = "test" & gt; ; & Lt; ul & gt; {{Item in Model}}} 
  • gt; {{item.ID}} {{/ each}} {{Outlet}} & lt; / script & gt;
  • When I log out of the data I have returned to, then something similar looks like:

      object {dummyArray: Array [4]} Dummiere: Array [4] 0: Object ID: 11111: Object ID: 1112 2: Object ID: 1113 3: Object I D: 1114  

    The app runs with no errors, but when I do not have the page populated with any data on my test page

    Your problem is that your synchronous code is not returning anything. Your model function returns App.Test.findAll () , which is nothing, you need to return a promise.

      findAll: function () {var results = []; Return the new Amber. RSVP.prakash (work (solution, reject) {ABER $ .ajax ({type: 'GET', url: 'mural', header: {'myahder'}, success: function (data) {data .dummyArray.forEach (Function (item) {result.push (App.Test.create (item))}}; resolution (result);}, error: function (request, text position, error) {console.log (error); (Error);}});}); }  

    No comments:

    Post a Comment