0
我是Emberjs的初學者,請仔細閱讀代碼,並指導我在哪裏錯了。Emberjs存儲錯誤 - 未捕獲TypeError:對象[對象對象]沒有方法'trasitionTo'
js文件
Sample = Ember.Application.create();
Sample.Router.map(function(){
this.route('view');
this.resource('add');
})
Add = Ember.Object.extend();
View = Ember.Object.extend();
Sample.AddNewRoute = Ember.Route.extend({
model:function(){
return Sample.Add.createRecord();
}
});
Sample.ViewController = Ember.ArrayController.extend();
Sample.AddController = Ember.ObjectController.extend({
content:[],
save:function(){
this.get("model.transaction");
this.get("target").trasitionTo('view');
}
});
Sample.ViewController = Ember.ArrayController.extend();
Sample.Store = DS.Store.extend({
revision:11,
adapter: DS.LSAdapter.create(),
});
Sample.Add = DS.Model.extend({
name: DS.attr("string"),
desig: DS.attr("string"),
age: DS.attr("integer")
});
.html file
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/jquery-1.9.1.js"></script>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/handlebars-1.0.0.js"></script>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/ember-1.0.0.js"></script>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/ember-data.js"></script>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/localstorage_adapter.js"></script>
<script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/sample.js"></script>
<meta charset=utf-8 />
<title>Demo application</title>
</head>
<body>
<script type="text/x-handlebars">
<h1>Welcome to Demo!</h1>
{{#link-to 'add'}}Add Member{{/link-to}}
{{#link-to 'view'}}View Members{{/link-to}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name ='add'>
<h1>Add member!</h1>
<form {{action 'save' on='submit'}}>
<br>{{#view Ember.TextField valueBinding="name" placeholder= "Enter the name"}}{{/view}}</br>
<br>{{#view Ember.TextField valueBinding="desig" placeholder= "Enter the designation"}}{{/view}}</br>
<br>{{#view Ember.TextField valueBinding="age" placeholder= "Enter the age"}}{{/view}}</br>
<br><button {{action "save"}}>Add Member</button></br>
</form>
</script>
<script type="text/x-handlebars" data-template-name ='view'>
<h3><strong>All Registered Members!</strong>
<br></br>
{{#each controller}}
<br>{{name}}</br>
<br>{{desig}}</br>
<br>{{age}}</br>
{{else}}
No members registered yet! :(
{{/each}}
</script>
enter code here
</body>
</html>
後,我點擊「添加成員按鈕,我收到以下錯誤:
遺漏的類型錯誤:對象的翻譯:有沒有方法‘trasitionTo’
這裏有兩件事:1.記錄2.資源。在您的原始代碼中,您將記錄和資源命名爲「添加」,並導致此問題。我的建議是將記錄名稱更改爲其他名稱。你不需要改變路線等... – VNarasimhaM
我改變了添加到添加成員。 AddMember = Ember.Object.extend(); ViewMember = Ember.Object.extend(); Sample.AddMemberNewRoute = Ember.Route.extend({ 模型:函數(){ 返回Sample.AddMember.createRecord();} }); Sample.ViewMemberController = Ember.ArrayController.extend(); ()); this.get('router.target')。'trasitionTo('); '; } }); 但我得到了-Uncaught錯誤:雖然我在控制器中定義了方法,但沒有處理事件'save'error – user2730628