我是新來的EmberJS,我建立了一個簡單的項目,使用ember-cli,我在我的應用程序中有以下代碼: routes /person.jsEmberJS:用初始路由,控制器和模板與v1.11.0(noobie)
import Ember from "ember";
export default Ember.Route.extend({
setupController: function(controller, person) {
controller.set('model', person);
},
model: function() {
return this.store.find('person', 1); // returns a promise that will resolve
},
});
模型/ person.js
import DS from "ember-data";
let Person = DS.Model.extend({
name: DS.attr('string'),
birthDate: DS.attr('string'),
});
Person.reopenClass({
FIXTURES: [
{ id: 1, name: 'Jack Sparrow', birthDate: 'Glowacki' },
{ id: 2, name: 'Long John Silver' , birthDate: 'Dale' }
]
});
export default Person;
控制器/ person.js
個import Ember from "ember";
export default Ember.ObjectController.extend({
findPerson: function(){
//do a HTTP call to the mzalendo API
},
});
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.route('person', { path: '/person' });
});
模板/ person.hbs
<strong>Name: {{name}} </strong>
當我運行服務器和去http://localhost:4200/persons無負載和有沒有錯誤,我我在這裏錯過了什麼?
編輯
發射了JS控制檯,並看到了這個錯誤:
GET http://localhost:4200/people 404 (Not Found)jQuery.ajaxTransport.send @ jquery.js:9659jQuery.extend.ajax @ jquery.js:9210ember$data$lib$system$adapter$$Adapter.extend.ajax @ rest-adapter.js:792initializePromise @ ember.debug.js:46984Promise @ ember.debug.js:48612ember$data$lib$system$adapter$$Adapter.extend.ajax @ rest-adapter.js:776ember$data$lib$system$adapter$$Adapter.extend.findAll @ rest-adapter.js:371ember$data$lib$system$store$finders$$_findAll @ finders.js:115ember$data$lib$system$store$$Service.extend._fetchAll @ store.js:997ember$data$lib$system$store$$Service.extend.fetchAll @ store.js:570ember$data$lib$system$store$$Service.extend.findAll @ store.js:978ember$data$lib$system$store$$Service.extend.find @ store.js:514model @ persons.js:7EmberObject.default.extend.deserialize @ ember.debug.js:22623applyHook @ ember.debug.js:46611HandlerInfo.runSharedModelHook @ ember.debug.js:44612subclass.getModel @ ember.debug.js:44838__exports__.bind @ ember.debug.js:46480tryCatch @ ember.debug.js:46937invokeCallback @ ember.debug.js:46949publish @ ember.debug.js:46920(anonymous function) @ ember.debug.js:27239Queue.invoke @ ember.debug.js:871Queue.flush @ ember.debug.js:936DeferredActionQueues.flush @ ember.debug.js:741Backburner.end @ ember.debug.js:166Backburner.run @ ember.debug.js:221Backburner.join @ ember.debug.js:240run.join @ ember.debug.js:15966run.bind @ ember.debug.js:16021jQuery.Callbacks.fire @ jquery.js:3143jQuery.Callbacks.self.fireWith @ jquery.js:3255jQuery.extend.ready @ jquery.js:3467completed @ jquery.js:3498
ember.debug.js:24085 Error while processing route: persons Not Found Error: Not Found
at ember$data$lib$system$adapter$$Adapter.extend.ajaxError (http://localhost:4200/assets/vendor.js:62085:35)
at ember$data$lib$system$adapter$$Adapter.extend.ajax.Ember.RSVP.Promise.hash.error (http://localhost:4200/assets/vendor.js:62160:45)
at jQuery.Callbacks.fire (http://localhost:4200/assets/vendor.js:3345:30)
at Object.jQuery.Callbacks.self.fireWith [as rejectWith] (http://localhost:4200/assets/vendor.js:3457:7)
at done (http://localhost:4200/assets/vendor.js:9513:14)
at XMLHttpRequest.jQuery.ajaxTransport.send.callback (http://localhost:4200/assets/vendor.js:9915:8)
不知道其中/人路由是從
添加適配器並刪除setUpController,仍然沒有加載,一個錯誤將幫助我找出發生了什麼.. – jwesonga
編輯添加,你需要添加一個路由 –
不知道如何處理這個了.. – jwesonga