2015-07-19 33 views
1

router.js無法加載形式創建模型的新實例

Router.map(function() { 
    this.route('concepts'); 
    this.route('create-concept', { path: '/concepts/new' }); 
    this.route('concept', { path: '/concepts/:id' }); 
}); 

控制器/創建-concept.js

import Ember from 'ember'; 

export default Ember.Controller.extend({ 
    actions: { 
    create: function() { 
     var concept = this.store.createRecord('concept', { 
     description: this.get('description').trim() 
     }); 
     this.set('description', ''); 
     concept.save(); 
    } 
    } 
}); 

模板/創建概念.js has

{{textarea value="description"}} 

{{action 'create'}} 

路由/創建-concept.js只是默認

import Ember from 'ember'; 

export default Ember.Route.extend({ 
}); 

當我去到我的瀏覽器的URL /concepts/new,但是,我只是得到我的瀏覽器中的錯誤

Uncaught TypeError: Cannot read property 'getAttribute' of undefined 

。我不知道這個通用錯誤的原因是什麼,關於這個文檔似乎很稀少......

編輯 - 當我訪問/概念,並點擊鏈接到/概念/新的,它顯示

Preparing to transition from 'concepts' to ' create-concept' 
Transitioned into 'create-concept' 

所以它會出現,它並找到正確的路線

因爲它很難複製並粘貼此出於某種原因,這裏的堆棧跟蹤的部分截圖:

EDIT 2 - Minimal code demonstrating problem

stack trace

+0

你將包括堆棧跟蹤,在我添加了如下答案的信息折騰只是一個部分,並沒有回答你的第一個問題。 – Kingpin2k

+0

另外,我認爲你已經有了一個潛在的衝突路線,儘管Ember可能會很好,但我並不積極,它總能看到'/ concepts/new'爲id爲'new'的'概念'路線' – Kingpin2k

+0

我可能會簡化,儘可能多地發表評論,如果你想在emberjs.jsbin.com上嘗試和複製,這也會有所幫助。 – Kingpin2k

回答

2

我不認爲你真的想value="description",你可能意味着value=description

一個文本字符串description分配給value屬性,其他將屬性description綁定到value屬性。

您的行爲需要真正附加到某個東西!一個div,按鈕,錨標籤。

<div {{action 'create'}}>blah</div> 

<button {{action 'create'}}>blah</button> 

http://guides.emberjs.com/v1.10.0/templates/actions/

+0

哦!哈哈哈應該仔細看看這個例子,非常感謝:) – wrongusername

相關問題