Ember template won't output data


#1

I’m creating a Node-Webkit application using Ember. It’s a fairly simple app so I’m not using Ember data, but instead just retrieving the data from the file system via Node, parsing it, then returning it to the page. The JSON is valid, Ember displays the correct object in console when I {{log person}} but the values aren’t there. I’ve tried changing key names just in case, but that didn’t work. Can anyone tell me what might be going wrong? Here’s the relevant snippets of code:

JSON

[
  {
    "first_name ": "Adam",
    "last_name ": "Wilczek",
    "department ": "Product"
  },
  {
    "first_name ": "AJ",
    "last_name ": "Nance",
    "department ": "Sales"
  },
  {
    "first_name ": "Alex",
    "last_name ": "Ezell",
    "department ": "Product"
  },
  {
    "first_name ": "Andy",
    "last_name ": "Matthews",
    "department ": "Product"
  },
  {
    "first_name ": "Anna",
    "last_name ": "Talley",
    "department ": "Services "
  }
]

People Controller

App.PeopleController = Ember.ArrayController.extend({
  content: [],
  loadData: function(){
    var controller = this;
    utils.loadJSON(
      function(data){
        controller.set('content', data);
      },
      function(data) {
        // TODO: handle error
      }
    );
  }
});

loadJSON

publicMethods.loadJSON = function(success, failure) {
  var fileToLoad = dataPath + '/people.json';
  fs.readFile(fileToLoad, function(error, data){
    if (error) {
      failure(error);
    } else {
      var peeps = data.toString();
      success(JSON.parse(peeps));
    }
  });
};

template

<script type="text/x-handlebars" data-template-name="people">
  <h2>People route</h2>
  <p>This is where we show the list of people</p>
  {{#each person in controller}}
    <p>
      {{log person}}
      first_name: {{person.first_name}}<br />
      last_name: {{person.last_name}}<br />
      department: {{person.department}}<br />
    </p>
  {{/each}}
</script>

Here’s a screenshot of the console with Ember versions and the output from the {{log person}} statement:

I’m at a loss for words. Can anyone offer input please?


#2

If need be I’m happy to post all of the code for review, it just won’t help because the source data is behind a firewall.

Oh, and also, I do not have a model for this data, I’m simply loading in the raw JSON.


#3

Just throwing this out there, but could it be the spaces after your keys in the raw json data? "first_name "


#4

Hot damn you’re right @adeguzm1! I didn’t even notice that. I’m creating this JSON file by converting it from Excel in another method (not shown). Looks like the extra space is actually in the Excel file itself. Great catch, thanks so much for your time!