Question

In Ember, how would you manipulate a specific json string.

Lets say I want to manipulate every "field2" so it says "stringplusmore" instead of just "string".

I'm confused whether I should use Enumerables or something else. Or it should be in the Array or Object controller. Or maybe a view?

An example would be appreciated. Thanks!

[  
   {  
      "field1":"string",
      "field2":"string",
   },
   {  
      "field1":"string",
      "field2":"string",
   }
]
Was it helpful?

Solution

If you're just modifying the json before it hits the page, do it in the route.

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return $.getJSON('/items').then(function(data){
      data.forEach(function(item){
        item.field2 += 'plusmore';
      });
      return data;
    });
  }
});

http://emberjs.jsbin.com/OxIDiVU/881/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top