How to map a data to a segment if the data is not in a collection in Kony Studio?
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:
- Parse your JSON data, while mentioning the
id
in the service editor, please keep in mind to use theid
of the children widgets of the segment as theid
for output parameter. - After parsing the you must get a collection which is similar as following
[ { "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.
- After this use the set data method of the Kony.ui.segment widget to set the data.
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.
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.
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);