mercredi 16 septembre 2015

Ember Data Undefined in Template But Accessible in Console

I am relatively new to ember and am just taking a look at it for the first time, I am using ember-cli-mirage as a mock server and am having some issues.

In my models/groups.js I have

export default DS.Model.extend({
  name: DS.attr('string'),
  serverType: DS.attr('string', {defaultValue: 'Web Server'}),
  protectionMode: DS.attr('string', {defaultValue: 'High'}),
  protectionLevel: DS.attr('string', {defaultValue: '=)'}),
  bps: DS.attr('number'),
  pps: DS.attr('number'),
  protectedHosts: DS.attr('string', {defualtValue: '1.0.0.0'}),
  lastModified: DS.attr('number', {defualtValue: 1}),
  complete: DS.attr('string')
});

I originally did not have default values in anywhere but once I added them content showed up in my templates for serverType, protectionMode, protectionLevel but not lastModified or protectedHosts

My mirage/config.js

export default function() {
  this.get('/groups', function(db, request) {
    console.log(db.groups)
    return {
      data: db.groups.map(attrs => (
        {type: 'groups', id: attrs.id, attributes: attrs}
      ))
    };
  });

  this.post('/groups', function(db, request) {
    let attrs = JSON.parse(request.requestBody);
    let group = db.groups.insert(attrs);
    return {
      data: {
        type: 'groups',
        id: group.id,
        attributes: group
      }
    };
  });

  this.patch('/groups/:id', function(db, request) {
    let attrs = JSON.parse(request.requestBody);
    let group = db.groups.update(attrs.data.id, attrs.data.attributes);
    return {
      data: {
        type: 'groups',
        id: group.id,
        attributes: group
      }
    };
  });

  this.del('/groups/:id');
}

The console logging I am doing in the /groups get is showing all of the correct data from my mirage/factories

mirage/factories/groups.js

import Mirage, {faker} from 'ember-cli-mirage';

export default Mirage.Factory.extend({  
    name(i) { return `Protection Group ${i + 1}`; },
    serverType(i) { return `Custom Server Type ${i + 1}`;},
    protectionMode: 'High',
    protectionLevel: '=)',
    lastModified(i) { return `${i+1} Weeks`; },
    bps(i) { return parseInt(Math.floor((Math.random() * i) + 100 * i)) },
    pps(i) { return parseInt(Math.floor((Math.random() * 100) + i)) },
    protectedHosts(i) { return `10.1.2.1${i+1}`; },
    complete: false
});

Anyone have any idea why some data is showing up as undefined and some is not and why some default values are working but some are not?




Aucun commentaire:

Enregistrer un commentaire