これは私の前の質問に関連しています。そこでの答えは問題を解決するように見えました。しかし、私は文字通り別のルートからまったく同じことを行っていますが、今ではエラーが発生します。アプリケーションは ajax 関数を 2 回渡します。初めて、TypeError が発生します。ページをリロードすると、関数は正しく実行されます。私はドキュメントで知っていますが、定義されたオブジェクトを作成してオブジェクトを作成する必要があると述べています。関数が呼び出されたときに関数を実行するために、拡張コントローラーを作成する必要がある例を教えてください。
エラーが表示されます: TypeError: this.init is undefined
これが私のルートです:
App.RegisterPickRoute = Em.Route.extend({
redirect: function() {
var registerTestController=this.controllerFor('registerTest')
var isRegistered=registerTestController.registerContacts();
if(!isRegistered)
this.transitionTo('registerTest');
else
alert('holla')
}
});
これが私のコントローラーの私の機能です:
registerContacts: function(){
var isRegistered=false;
var self=this
self.contactsToAdd=self.get('contactList').filterProperty('isSelected', true);
$.ajax({
type: 'POST',
cache: false,
url: contextPath + 'user/regTest',
data:{contactList:self.contactsToAdd},
success: function(data) {
isRegistered=true;
},
error: function(jqXHR, textStatus, errorThrown) {
isRegistered=false;
},
async: false
});
return isRegistered
}