You need to sign in to do that
Don't have an account?
Sujit Das@Accenture
JSON.stringify: Converting Task[] into JSON string returns only 1st row value
Hi,
When I am trying to convert a array of task into JSON string in my lightning controller, only the 1st element is returned always even though the array has more values. Here is the code. Has anyone faced the same issue.
Component:
<aura:attribute type="Task[]" name="listTask" />
Controller:
var taskList = component.get("v.listTask"); //tried var taskList = component.get("v.listTask").slice(); as well
console.log(taskList.length); //Length is returned correctly e.g. 3
//converting the array into JSON string
var JSONStr = JSON.stringify(taskList);
console.log(JSONStr); // [{"sobjectType":"Task","ActivityDate":"2016-3-3","Status":"In Progress","Subject":"task1"},[],[]]
When I am trying to convert a array of task into JSON string in my lightning controller, only the 1st element is returned always even though the array has more values. Here is the code. Has anyone faced the same issue.
Component:
<aura:attribute type="Task[]" name="listTask" />
Controller:
var taskList = component.get("v.listTask"); //tried var taskList = component.get("v.listTask").slice(); as well
console.log(taskList.length); //Length is returned correctly e.g. 3
//converting the array into JSON string
var JSONStr = JSON.stringify(taskList);
console.log(JSONStr); // [{"sobjectType":"Task","ActivityDate":"2016-3-3","Status":"In Progress","Subject":"task1"},[],[]]
Naruto
Did you got the answer, if 'yes' could you post it.
Dinesh_Kumar_Nagarathinam
Can you show the format of taskList? Do console.log(taskList) and post the result here.so that we can analyze it.