this is the main app in ember.js
app/templates/application.hbs
<ul>
<LinkTo @route="print-user" >Print User</LinkTo>
</ul>
This is the code to get the json-array response from servlet
app/components/print-user.js
import Component from '@glimmer/component';
import {action} from "@ember/object";
import {tracked} from "@glimmer/tracking";
export default class PrintUserComponent extends Component {
@tracked search="";
@tracked print="";
@tracked gotresponse=false;
@action
async searchuser (searchtext){
let response=await fetch("/UserManagement/SearchServlet",
{ method: "POST",
body: JSON.stringify({
"type": "search",
"searchtext": searchtext
})
});
let parsed=await response.json();
this.gotresponse=true;
this.search=parsed;
}
async deleteuser (id,firstname,lastname,mailid){
let response=await fetch("/UserManagement/UserManagementServlet",
{ method: "POST",
body: JSON.stringify({
"type": "delete",
"id": id,
"firstname":firstname,
"lastname":lastname,
"mailid":mailid
})
});
let parsed=await response.json();
alert(parsed.status);
}
}
This is the hbs code to print the user table in webpage
app/components/print-user.hbs
<input5></input5>
<searchbutton >Search</searchbutton>
<printbutton >Print User</printbutton>
<table class="styled-table">
<thead>
<tr><th>User Id</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Mailid</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td><button >Delete</button></td>
</tr>
</tbody>
</table>
I need to print the user data while clicking the print user in application.hbs It is working properly when I click search button. I Don't know how to print the user details without clicking button....
Aucun commentaire:
Enregistrer un commentaire