尝试使用ember创建一个web应用程序,该应用程序获取登录信息并路由到另一个页面。它获取登录信息和整个路由,并显示错误Uncaught ReferenceError: Controller is not defined
我的登录控制器代码,它获取登录信息并将其路由到roomselect路由
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
//import EmberResolver from 'ember-resolver';
import Ember from 'ember';
import $ from 'jquery';
export default class LoginsController extends Controller {
@tracked result = 0;
@service router;
//canLogin:true;
@action
get() {
var that = this;
var uname = document.getElementById('uname').value;
var mobile = document.getElementById('mobile').value;
console.log('name ->' + uname);
console.log('mobile ->' + mobile);
$.ajax({
url: 'http://localhost:8080/hotelres/AuthenticationServlet',
method: 'GET',
data: { uname: uname, mobile: mobile },
success: function (response) {
that.result = response;
console.log('response-> ' + response);
if (that.result == 1) {
alert('sucess');
that.transitionToRoute('roomselect');//----> routing
console.log(that.result);
} else {
alert('Login failed');
}
},
error: function (xhr, status, error) {
var errorMessage = xhr.status + ':' + xhr.statusText;
alert('error' + errorMessage);
},
});
}
}
我的roomselect控制器路由将从servlet和显示控制器接收数据,该路由未定义
import { use, resource } from 'ember-resources';
import { tracked } from '@glimmer/tracking';
class RequestState {
@tracked value;
@tracked error;
get isPending() {
return !this.error && !this.value;
}
}
export default class RoomselectController extends Controller {
@service router;
@use request = resource(({ on }) => {
const mobile = '123123123';
const state = new RequestState();
$.ajax({
url: 'My',
method: 'GET',
dataType: 'json',
data: { mobile },
success: (response) => state.value = response ,
error: (xhr, status, error) => state.error = `${status}: ${xhr.statusText}`,
});
return state;
});
get result() {
return this.request.value || [];
}
}
房间控制器。hbs代码
{{#if this.request.isPending}}
loading data...
{{/if}}
<table border ="1">
<thead>
<tr>
<th>Capacity</th>
<th>Price</th>
<th>Room Type</th>
<th>Room No</th>
</tr>
</thead>
<tbody>
{{#each this.result as |row|}}
<tr>
{{#each-in row as |key value|}}
{{value}}
{{/each-in}}
</tr>
{{/each}}
</tbody>
</table>
路由器。js文件
import EmberRouter from '@ember/routing/router';
import config from 'embu/config/environment';
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}
Router.map(function () {
this.route('logins', function () {
this.route('testt');
});
this.route('register');
this.route('succcess');
this.route('error');
this.route('roomselect');
});
1条答案
按热度按时间inb24sb21#
似乎我还没有在房间选择控制器js文件中导入控制器模块,添加
import Controller from '@ember/controller';
解决了这个问题