[英]Ember.js Unable to find view at path when returning to route
我有一個簡單的示例ember.js應用程序,我想在索引模板上包含一個視圖。
這適用於初始渲染。
當我鏈接到第二條路線並返回原始路線時,出現錯誤“ 無法在路徑'App.testView'中找到視圖”
示例代碼: JSFiddle
HTML頁面...
<div id="test"></div>
<script type="text/x-handlebars">
<h1>Test Layout</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Index Template</h2>
<p>{{#linkTo test}}test route{{/linkTo}}</p>
<div>{{view App.testView}}</div>
</script>
<script type="text/x-handlebars" data-template-name="test">
<h2>Test Template</h2>
<p>{{#linkTo index}}index route{{/linkTo}}</p>
</script>
<script type="text/x-handlebars" data-template-name="testview">
<p>Test View</p>
</script>
Javascript ...
window.App = Ember.Application.create();
App.Router.map(function() {
this.route("test");
});
App.testView = Ember.View.create({
templateName: 'testview'
});
使用Ember.View.extend
而不是Ember.View.create
將解決此問題。
根據{{view}}
助手的Ember API ,您需要向其傳遞一個類,而不是一個實例。 助手將創建一個新的View
實例並將其插入。
能夠識別的一個簡單語法錯誤是未添加路徑屬性。 使用此更新代碼Router.map()
App.Router.map(function() {
this.route("test",{path:"/"});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.