Reputation: 678
I am using Kony Studio 5.5 for cross platform development. I retrieve data by using a JSON service. I want to print my data in a segment, but I can't map some of it because it is not in a collection.
"chartStat": " CHART NOT PREPARED ",
"passengers": [{
"trainBookingBerth": "RAC9 , 8,GN ",
"trainCurrentStatus": " CNF ",
"trainPassenger": "Passenger 1"
}],
"trainBoard": "Kovilpatti",
"trainBoardCode": "CVP",
"trainDest": "Chennai Egmore",
In the above payload I can map passengers
to the segment but I also want to map trainBoard
, trainBoardCode
and trainDest
to it.
Upvotes: 3
Views: 3962
Reputation: 473
You need to follow this structure to put data in Segment...
var data=[
[{lblHeading:"Section1"},[{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"}]],
[{lblHeading:"Section2"},[{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"}]],
[{lblHeading:"Section3"},[{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"}]],
[{lblHeading:"Section34"},[{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"},{samplelabel:"1"}]]
];
this.view.segmentList.setData(data);
Upvotes: 0
Reputation: 5478
This question was asked a very long time ago, but for anyone wondering how to do this, you can use the addDataAt
and setDataAt
methods you can use to respectively insert or replace a single row of data at a specified position in a Segment.
From Kony's Widget Programmer's Guide about the addDataAt
method:
Allows you to add one row of data at a given index or within a section.
addDataAt(data, rowIndex, sectionIndex)
and about the setDataAt
method:
Allows you to set data or modify an existing data of a row or within a section.
setDataAt(data, rowIndex, sectionIndex)
I hope this helps others in the future.
Upvotes: 0
Reputation: 424
If you are using the Kony service editor, parse the output according to your requirement. By parsing the result one can isolate the required parameter -i.e.: Filter the result returned from service- that are only required at the client side and in a format that we can specify.
If you have three labels in the segment and you want to show the passengers
details return by the service, please follow these steps:
id
in the service editor, please keep in mind to use the id
of the children widgets of the segment as the id
for output parameter. [
{ "labelOneId": "RAC1 , 8,GN ", "labelTwoId": " CNF 1", "labelThreeId": "Passenger 1" },
{ "labelOneId": "RAC2 , 8,GN ", "labelTwoId": " CNF 2", "labelThreeId": "Passenger 2" },
{ "labelOneId": "RAC3 , 8,GN ", "labelTwoId": " CNF 3", "labelThreeId": "Passenger 3" },
{ "labelOneId": "RAC3 , 8,GN ", "labelTwoId": " CNF 4", "labelThreeId": "Passenger 4" }
]
Where the labelOneId
, labelTwoId
and labelThreeId
will be the ids used for children of the segment where the data need to be displayed.
Note: If you did not use the id of the children widget then you will have to format the data using a "for" loop iterator.
Extracting the value from the sample value provided in your question:
var jsonReturned={
"chartStat": " CHART NOT PREPARED ",
"passengers": [{
"trainBookingBerth": "RAC9 , 8,GN ",
"trainCurrentStatus": " CNF ",
"trainPassenger": "Passenger 1"
}],
"trainBoard": "Kovilpatti",
"trainBoardCode": "CVP",
"trainDest": "Chennai Egmore"
};
var oneVal = jsonReturned["passengers"]["0"]["trainBookingBerth"];
var twoVal = jsonReturned["passengers"]["0"]["trainCurrentStatus"];
var threeVal = jsonReturned["passengers"]["0"]["trainPassenger"];
var fourVal = jsonReturned["trainBoard"];
var fiveVal = jsonReturned["trainDest"];
var dataForSegment = [{
"labelOneId": oneVal,
"labelTwoId": twoVal,
"labelThreeId": threeVal,
"lableFourId": fourVal,
"labelFiveId": fiveVal
}];
Try setting this in the as the dataForSegment
as segment data. If you want to add any additional value you have to similarly extract the data from the JSON object and form a collection suitable for your segment.
Upvotes: 2