EMBER-断言失败:加载路径时出错:TypeError:Object [object Object]没有方法'addArrayObserver'

时间:2014-01-02 16:37:03

标签: javascript jquery arrays ember.js

当我将所有内容作为一个数组传递时,我得到了所需的结果,即我的嵌套路由在父模板中显示它的模板。请参阅codepen resume page

现在,当我将其转换为灯具数据时,我会收到一个错误:

Assertion failed: Error while loading route: TypeError: Object [object Object] has no method 'addArrayObserver' 

只要我将resume[1]作为参数传递,它就会中断。我很困惑,为什么这在我的笔中工作,我想知道如何在我使用灯具时修复它

afterModel: function(resume, transition) {
  this.transitionTo('company', resume[1]);
}

完整代码

App = Ember.Application.create({
  LOG_TRANSITIONS: true
});

App.ApplicationAdapter = DS.FixtureAdapter.extend();

// Routes
App.Router.map(function() {
  this.resource('resume', function(){
    this.resource('company', {path: '/:company_id'});
  });
  this.route('contact');
});

App.ResumeRoute = Ember.Route.extend({
  model: function() {
    return this.store.findAll('company');
  }
  ,
  afterModel: function(resume, transition) {
    this.transitionTo('company', resume[1]);
  }
});

App.Company = DS.Model.extend({
  companyName: DS.attr(''),
  jobTitle: DS.attr(''),
  jobDescription: DS.attr(''),
  image: DS.attr(''),
  dates: DS.attr('')
});

// Model Data
App.Company.FIXTURES = [
  {
    id: '1',
    companyName: 'Brandingbrand',
    jobTitle: 'Frontend Web Developer',
    jobDescription: 'Branding Brand powers mobile commerce sites and apps for over 200 of the worlds leading retailers, including American Eagle Outfitters, Crate & Barrel, Ralph Lauren, and Sephora. Our transformative technology is proven, reliable, and limitless. Our work is regularly noted by independent research firms, including Forrester and L2. We are also on CrunchBase. And Facebook. And Twitter. The Branding Brand platform scales to meet client goals and supports all forms of smartphone and tablet output. It requires no IT resources, no systems integration, and no web development. Because our inputs are as limitless as our outputs, we can easily transform any aspect of a desktop site into a unique, optimized experience for smartphones, tablets, or in-store. ',
    image: 'http://b.vimeocdn.com/ps/103/913/1039135_300.jpg',
    dates: 'November 2013 – Current | Pittsburgh Area'
  },
  {
    id: '2',
    companyName: 'PPG Industries',
    jobTitle: 'Frontend Web Designer',
    jobDescription: 'PPG, the worlds leading maker of transportation coatings and a major global supplier of industrial and packaging coatings, flat and fabricated glass, continuous-strand fiber glass, and industrial and specialty chemicals. Our many PPG technologies have been recognized with prestigious R&D 100 Awards and recipients have included. We are also the developers of Transitions® plastic photochromic eyewear lenses that automatically darken when exposed to sunlight. We developed a fiber glass yarn destined to revolutionize the manufacture of circuit boards for computers and other electronic devices Examples of our continuing emphasis on developing high-technology products include.',
    image: 'https://www.xeikon.com/sites/default/files/images/ppg-industries.jpeg',
    dates: 'August 2012 – August 2013 | Pittsburgh Area'
  },
  {
    id: '3',
    companyName: 'Kolano Design',
    jobTitle: 'Graphic Designer',
    jobDescription: 'Kolano Design is a visual marketing firm, based in Pittsburgh, with expertise in graphics, signage and interiors. The graphics team includes media and communications specialists who create strong corporate identities and adapt them to print, advertising, packaging and web. The signage team includes architects and industrial designers who develop signs that build brands and address complex wayfinding challenges. The interiors team includes designers and product inventors who give shape to high profile corporate and residential spaces and consumer products. We hope you enjoy paging through some of our recent work. Give us a call at 412-661-9000. Call us today.',
    image: 'http://pghdesigners.com/images/portfolio/138.jpg',
    dates: 'August 2012 – August 2013 | Pittsburgh Area'
  },
  {
    id: '4',
    companyName: 'Whirl Magazine',
    jobTitle: 'Front End Web Designer',
    jobDescription: 'Founded in 2001, WHIRL is Western Pennsylvanias Premier Lifestyle Magazine. Twelve times per year, WHIRL promotes the people, places, and businesses that help Pittsburgh continue to be "Americas Most Livable City." From fundraisers and galas to after-work happy hours, WHIRL provides a behind-the-scenes look at Pittsburghs vibrant social scene. The success of the magazine is founded on the support of the community and WHIRLs goal to showcase the best of Western Pennsylvania living. Since its foundation, WHIRL Magazine has expanded into a multi-faceted publishing company, including the bi-monthly Edible Allegheny, Pittsburghs main resource for local food and farms.',
    image: 'http://www.themodernmatchmaker.com/wp-content/uploads/2012/08/whirl-magazine-dating-news-articles.jpg',
    dates: 'April 2011 – July 2011 | Pittsburgh Area'
  },
  {
    id: '5',
    companyName: 'Pittsburgh Technical Institute',
    jobTitle: 'Visual Communications Assistant',
    jobDescription: 'Probably the most important advantage for students is the assistance provided by the Career Services department in job search and career assistance. Students can explore employment opportunities on a local, regional and national level through PTI’s network of contacts. All associate degree and many certificate students have the opportunity to experience an industry internship or clinical experience. This further enhances the hands-on experience students enjoy across all programs and builds a strong portfolio. Probably the most important advantage for students is the assistance provided by the Career Services department. This is all without doubt why people come.',
    image: 'http://media.prleap.com/image/17002/full/PTI.png',
    dates: 'March 2010 – July 2011 | Oakdale PA'
  }
 ];

当我在console.log('company',resume 1)时; - 公司未定义。当我在console.log('resume',resume);和console.log('company',resume);他们都分别回归:

resume 
Class {type: function, store: Class, isLoaded: true, isUpdating: false, constructor: function…}
__ember1388681292354: "ember270"
__ember1388681292354_meta: Meta
_super: undefined
arrangedContent: (...)
content: (...)
get content: function () {
set content: function (value) {
isLoaded: true
isUpdating: false
store: Class
toString: function () { return ret; }
type: App.Company
__proto__: Object

1 个答案:

答案 0 :(得分:1)

resume不是数组,它是一个集合,因此resume[0]不存在,您应该使用resume.objectAt(0)