简体   繁体   English

Handlebars模板不会渲染ember数据对象

[英]Handlebars template won't render ember data object

I've built an ember front-end app that consumes an API made with rails in another application. 我已经构建了一个ember前端应用程序,该应用程序使用在另一个应用程序中使用rails制作的API。 The ember app is successfully requesting and receiving data from the rails api and one of my handlebars template (the index page that displays a list of all of the Graduates from my Graduates model) is working fine. ember应用程序成功地从rails api请求和接收数据,我的一个把手模板(显示我毕业生模型中所有毕业生的列表的索引页)工作正常。 The page meant to display individual graduates however is not able to render data about those individual graduates. 然而,用于显示个别毕业生的页面无法呈现有关这些个别毕业生的数据。 Although when I open the ember tool in the developer console in my browser (Chrome), that data is present. 虽然当我在浏览器(Chrome)中的开发者控制台中打开ember工具时,该数据仍然存在。

I'm new to ember and I've been trying to solve this for 2 days but am totally stumped, any help would be greatly appreciated! 我是新来的余烬,我一直试图解决这个问题2天,但我完全难过,任何帮助都将不胜感激!

app/adapters/application.js: 应用程序/适配器/ application.js中:

import DS from 'ember-data';

export default DS.ActiveModelAdapter.extend({
   namespace: 'api/v1',
   host: 'http://localhost:3000'
});

app/models/graduate.js: 应用程序/模型/ graduate.js:

import DS from 'ember-data';

export default DS.Model.extend({
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  cohort: DS.attr('string'),
  currentJob: DS.attr('string'),
  bio: DS.attr('string'),
  news: DS.attr('string'),
  website: DS.attr('string'),
  picture: DS.attr('string'),
  createdAt: DS.attr('date'),
  updatedAt: DS.attr('date')
  });

routes/graduates/index.js: 路线/毕业生/ index.js:

import Ember from 'ember';

export default Ember.Route.extend({
   model: function() {
      return this.store.find('graduate');
   }
});

routes/graduate.js: 路线/ graduate.js:

import Ember from 'ember';

 export default Ember.Route.extend({
    model: function(params) {
       return this.store.find('graduate', params.graduate_id);
    }
 });

app/router.js: 应用程序/ router.js:

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
 });

export default Router.map(function() {
   this.resource('graduates', function() {
     this.resource('graduate', { path: '/:graduate_id' });
     });
 });

environment.js: environment.js:

/* jshint node: true */

module.exports = function(environment) {
  var ENV = {
    contentSecurityPolicy: {
    'connect-src': "'self' http://localhost:3000",
     'default-src': "'none' http://localhost:3000",
     'script-src': "'self'",
     'font-src': "'self' http://localhost:3000",
     'img-src': "'self' http://localhost:3000",
     'style-src': "'self' http://localhost:3000 'unsafe-inline",
     'media-src': "'self' http://localhost:3000"
  },


modulePrefix: 'flatbook-front',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
  FEATURES: {
    // Here you can enable experimental features on an ember canary     
    build
    // e.g. 'with-controller': true
  }
},

 APP: {
  // Here you can pass flags/options to your application instance
  // when it is created
  }
 };

if (environment === 'development') {
  // ENV.APP.LOG_RESOLVER = true;
  // ENV.APP.LOG_ACTIVE_GENERATION = true;
  // ENV.APP.LOG_TRANSITIONS = true;
  // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
  // ENV.APP.LOG_VIEW_LOOKUPS = true;
}

 if (environment === 'test') {
   // Testem prefers this...
   ENV.baseURL = '/';
   ENV.locationType = 'none';

   // keep test console output quieter
   ENV.APP.LOG_ACTIVE_GENERATION = false;
   ENV.APP.LOG_VIEW_LOOKUPS = false;

   ENV.APP.rootElement = '#ember-testing';
 }

  if (environment === 'production') {

 }

  return ENV;
 };

app/templates/graduate.hbs: 应用程序/模板/ graduate.hbs:

<h1>{{firstName}} {{lastName}}</h1>

Should be 应该

  // app/templates/graduate.hbs
  <h1>{{model.firstName}} {{model.lastName}}</h1>

Your template 你的模板

<h1>{{firstName}} {{lastName}}</h1>

shows firstName and lastName properties from current controller (class Ember.Controller), but they are not set. 显示当前控制器(类Ember.Controller)的firstNamelastName属性,但它们未设置。

See the history of question here: http://emberjs.com/deprecations/v1.x/#toc_objectcontroller . 请在此处查看问题的历史记录: http//emberjs.com/deprecations/v1.x/#toc_objectcontroller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM