am trying to render a json array which is sent from a java servlet in ember. the work flow goes like follows
1.sending an ajax request to the servlet which will return the jsonobject
2.i will get the json object and try to render in the handlebar file
the problem is when i consoled the response it came with an indexes
0: {CAPACITY: '4', PRICE: '918', RTYPE: 'basic', ID: '4'}
1: {CAPACITY: '2', PRICE: '885', RTYPE: 'villa', ID: '8'}
2: {CAPACITY: '2', PRICE: '1579', RTYPE: 'villa', ID: '5'}
3: {CAPACITY: '1', PRICE: '1526', RTYPE: 'villa', ID: '1'}
but what the server sent was
{"CAPACITY":"4","PRICE":"918","RTYPE":"basic","ID":"4"}
{"CAPACITY":"2","PRICE":"885","RTYPE":"villa","ID":"8"}
{"CAPACITY":"2","PRICE":"1579","RTYPE":"villa","ID":"5"}
{"CAPACITY":"1","PRICE":"1526","RTYPE":"villa","ID":"1"}
the controller code
export default class RoomselectController extends Controller {
@service router;
@tracked obj = null ;
@tracked price =0;
get res(){
var dis = this;
const mobile = "123123123";
$.ajax({
url:'My',
method : 'GET',
dataType:'json',
data : {mobile:mobile},
success:function(response){
console.log(response);
dis.price = response[0].PRICE;//when rendered this works
dis.obj = response;//when changed to dis.obj = response[0] it renders the first
return response[0];
},
error: function(xhr,status,error){
var errorMessage = xhr.status + ": " + xhr.statusText;
alert("error " + errorMessage);
}
})
}
the .hbs code
<table border ="1">
<tr><td><b>Capacity</b></td><td><b>Price</b></td><td><b>Room Type</b></td><td><b>Room No</b></td></tr>
<td></td>
</table>
it is not working but when i use dis.obj = response[0]
it works and renders only the first index how to make it render every data?
Comments
Post a Comment