malik :
I am greeting response from mysql db and has bool value in it and i want to change 1= True and 0= false , here is my code. but replace function is not working :
TypeError: data[i].defaultstatus.replace is not a function
Here is my code :
var data= "select * from table"
for (var i = 0; i < data.length; i++) {
detail[i] = {
"id":data[i].id,
"Enabled":data[i].defaultstatus.replace('1', 'True' || '0','false'),
"CreationDate":data[i].created_at,
"ModificationDate":data[i].updated_at
}
}
resolve(detail)
UserCah :
i think The problem is how you are applying the replace function check what the value is before calling the replace function
try this :
var data= "select * from table"
for (var i = 0; i < data.length; i++) {
detail[i] = {
"id":data[i].id,
"Enabled": data[i].defaultstatus==1? data[i].defaultstatus.replace('1','True'):data[i].defaultstatus.replace('0', 'False')'
"CreationDate":data[i].created_at,
"ModificationDate":data[i].updated_at
}
}
resolve(detail)
OR
eliminate the replace function all together
var data= "select * from table"
for (var i = 0; i < data.length; i++) {
detail[i] = {
"id":data[i].id,
"Enabled": data[i].defaultstatus==1? 'true':'False
"CreationDate":data[i].created_at,
"ModificationDate":data[i].updated_at
}
}
resolve(detail)
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=402079&siteId=1