我正在從帶有問題和問題選項的 api 獲取資料。每個問題都有 4 個選項可供選擇。我已經在一個平面串列中呈現了結果。當我選擇單選按鈕時,我無法保存每個問題的值。看看我的代碼:
const Step3 = () => {
const [questions, setQuestions] = useState([]);
const [values, setValue] = useState()
const getQuestions = async () => {
const locale = 'sq'; // TODO: get current locale
const response = await apiStandarts.get(`/questions?locale=${locale}`, {
params: { _limit: MAX_QUESTIONS, active: 1, _sort:'sortId:ASC' },
});
setQuestions(response.data);
};
useEffect(() => {
getQuestions();
}, []);
const OptionList = (groupOption) => {
return (
<FlatList
data={groupOption.options}
keyExtractor={(result) => result.id.toString()}
renderItem={({ item, index}) => {
const clickedRadio = () => {
setValue(item.id)
}
return (
<View key={index}>
<Radio label={item.description} onChange={()=> clickedRadio() } />
</View>
);
}}
/>
);
};
return (
<View style={styles.container}>
<Text style={{ fontWeight: "bold", fontSize: 16, color: "#6B24AA" }}>
{t("Choose an option/Scroll for more questions")}
</Text>
<FlatList
data={questions}
keyExtractor={(result) => result.id.toString()}
renderItem={({ item, index }) => {
return (
<View style={styles.groupOptions} key={index}>
<Text>{item.description}</Text>
<OptionList options={item?.question_options}></OptionList>
</View>
);
}}
/>
</View>
)
}
下面是資料結構:
[
{
"id":11,
"description":"A ka organizata juaj politika dhe procedura t? brendshme organizative si pjes? e t? cilave parashikohet qart? m?nyra e ngritjes s? fondeve dhe e manaxhimit t? tyre n? m?nyr? etike?",
"active":true,
"sortId":11,
"locale":"sq",
"published_at":"2021-06-10T13:56:39.618Z",
"created_at":"2021-06-10T13:56:36.456Z",
"updated_at":"2021-10-06T09:18:29.403Z",
"organization_evaluation":null,
"questId":11,
"question_options":[
{
"id":44,
"question":11,
"description":"Organizata ka politika dhe procedura t? brendshme organizative si pjes? e t? cilave parashikohet shum? qart? m?nyra e ngritjes s? fondeve dhe e manaxhimit t? tyre n? m?nyr? etike.",
"points":4,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:15:34.685Z",
"created_at":"2021-06-10T14:15:31.675Z",
"updated_at":"2021-12-06T09:53:00.315Z",
"question_option_suggestion":{
"id":53,
"question_option":44,
"description":"Kjo ?sht? nj? praktik? shum? e mir? p?r mund?simin e qendrueshm?ris? organizative dhe transparenc?n e llogaridh?nien m? t? gjith? grupet e interesit. ?sht? e r?nd?sishme q? k?to procese t? mbahen dhe m?simet e nxjerra t? ndahen, n? m?nyr? q? organizatat e tjera t? mund t? ndjekin k?t? shembull. ",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:34.873Z",
"created_at":"2021-11-22T13:55:53.026Z",
"updated_at":"2021-12-06T09:53:00.317Z"
},
"organization_evaluation":null,
"questOptionId":44,
"sort":4
},
{
"id":41,
"question":11,
"description":"Organizata nuk ka politika dhe procedura t? tilla.",
"points":1,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:13:20.937Z",
"created_at":"2021-06-10T14:13:17.713Z",
"updated_at":"2021-12-06T09:51:40.886Z",
"question_option_suggestion":{
"id":50,
"question_option":41,
"description":"T? paturit e praktikave t? qarta dhe t? formalizuara p?r mbledhjen e fondeve dhe p?rdorimin e menaxhimin etik t? tyre, ?sht? nj? praktik? e k?shillueshme pasi p?rb?n nj? mjet p?r rritjen e qendruesh?mris? s? organizat?s, uljen e var?sis? nga nj? burim i caktuar fondesh, dhe krijimin e mund?sis? p?r t? qen? novator e i suksessh?m. Gjithashtu k?to praktika garantojn? njohjen gjer?sisht t? burimeve nga t? gjitha pal?t e interesuara. Kjo do t? sjell? m? shum? transparenc? dhe t? p?rmir?soj? p?rgjegjshm?rin?.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:22.267Z",
"created_at":"2021-11-22T13:54:07.049Z",
"updated_at":"2021-12-06T09:51:40.889Z"
},
"organization_evaluation":null,
"questOptionId":41,
"sort":1
},
{
"id":42,
"question":11,
"description":"Organizata nuk ka politika dhe procedura t? tilla por ndjek disa parime t? p?rgjithshme etike n? ngritjen e fondeve dhe manaxhimin e tyre.",
"points":2,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:13:57.687Z",
"created_at":"2021-06-10T14:13:49.677Z",
"updated_at":"2021-12-06T09:52:12.383Z",
"question_option_suggestion":{
"id":51,
"question_option":42,
"description":"T? paturit e praktikave t? qarta dhe t? formalizuara p?r mbledhjen e fondeve dhe p?rdorimin e menaxhimin etik t? tyre, ?sht? nj? praktik? e k?shillueshme pasi p?rb?n nj? mjet p?r rritjen e qendruesh?mris? s? organizat?s, uljen e var?sis? nga nj? burim i caktuar fondesh, dhe krijimin e mund?sis? p?r t? qen? novator e i suksessh?m. Gjithashtu k?to praktika garantojn? njohjen gjer?sisht t? burimeve nga t? gjitha pal?t e interesuara. Kjo do t? sjell? m? shum? transparenc? dhe t? p?rmir?soj? p?rgjegjshm?rin?.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:26.501Z",
"created_at":"2021-11-22T13:54:46.944Z",
"updated_at":"2021-12-06T09:52:12.385Z"
},
"organization_evaluation":null,
"questOptionId":42,
"sort":2
},
{
"id":43,
"question":11,
"description":"Organizata ka politika dhe procedura t? brendshme organizative si pjes? e t? cilave ka parashikime t? p?rgjithshme mbi m?nyr?n e ngritjes s? fondeve.",
"points":3,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:14:54.428Z",
"created_at":"2021-06-10T14:14:51.561Z",
"updated_at":"2021-12-06T09:52:39.514Z",
"question_option_suggestion":{
"id":52,
"question_option":43,
"description":"Zhvillimi dhe p?rdit?simi i vazhduesh?m i praktikave t? tilla, n? var?si dhe t? dinamikave zhvillimore t? organizat?s, siguron nj? p?rqasje novatore lidhur me garantimin e qendrueshm?ris? s? organizat?s. K?shillohet q? k?to politika t? jen? t? mir? detajuara, duke mund?suar jo vet?m nj? njohje sa m? t? gjer? nga t? gjith? grupet e interesit n? kuad?r t? transparenc?s dhe llogaridh?nies, por dhe zbatim t? sakt? t? tyre n? t? gjith? nivelet hirarkike.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:31.381Z",
"created_at":"2021-11-22T13:55:27.990Z",
"updated_at":"2021-12-06T09:52:39.518Z"
},
"organization_evaluation":null,
"questOptionId":43,
"sort":3
}
],
"commitments":[
{
"id":5,
"name":"Financim, Ngritje Fondesh dhe Manaxhim i Burimeve",
"icon":"fa-pencil",
"primary_color":"#348D73",
"secondary_color":"#06C088",
"active":true,
"published_at":"2021-05-13T08:09:20.077Z",
"created_at":"2021-05-13T08:09:11.107Z",
"updated_at":"2021-07-26T10:25:26.204Z",
"icon_color":"#33D0A1",
"locale":"sq",
"commitments_icon":5,
"commitment_icon":5,
"color_palette":"light_blue",
"link":"/financing",
"sortId":3
}
]
},
{
"id":13,
"description":"A kryen organizata juaj vler?sime periodike t? performanc?s t? punonj?sve dhe si? ",
"active":true,
"sortId":13,
"locale":"sq",
"published_at":"2021-06-10T13:57:37.862Z",
"created_at":"2021-06-10T13:57:34.723Z",
"updated_at":"2021-10-06T09:18:57.834Z",
"organization_evaluation":null,
"questId":13,
"question_options":[
{
"id":51,
"question":13,
"description":"Vler?simi i performanc?s s? punonj?sve b?het periodikisht me afate t? p?rcaktuara, , p?rmes nj? procedure t? formalizuar, por vet?m nga drejtuesi i organizat?s.",
"points":3,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:20:35.874Z",
"created_at":"2021-06-10T14:19:48.983Z",
"updated_at":"2021-12-06T09:55:01.718Z",
"question_option_suggestion":{
"id":60,
"question_option":51,
"description":"Kjo ?sht? nj? praktik? e mir? organizative e cila mund t? p?rmir?sohet m? tej me p?rfshirjen n? procedur? jo vet?m t? drejtuesit t? organizat?s por dhe niveleve t? tjera t? hierarkis?. Kjo p?rfshirje ofron nj? k?ndv?shtrim m? t? gjer? t? vler?simit t? p?rformanc?s n? raport dhe me pjes?n tjet?r t? stafit kryesisht supervizues. ",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:21:05.079Z",
"created_at":"2021-11-22T14:02:42.810Z",
"updated_at":"2021-12-06T09:55:01.724Z"
},
"organization_evaluation":null,
"questOptionId":51,
"sort":3
},
{
"id":49,
"question":13,
"description":"Organizata jon? nuk kryen vler?sime periodike t? performanc?s s? punonj?sve.",
"points":1,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:19:03.812Z",
"created_at":"2021-06-10T14:18:56.048Z",
"updated_at":"2021-12-06T09:54:26.197Z",
"question_option_suggestion":{
"id":58,
"question_option":49,
"description":"Vler?simi i performanc?s s? burimeve njer?zore ?sht? nj? aspekt shum? i r?nd?sish?m p?r t? analizuar ecurin? e organizat?s, rregullimet e mundshme q? mund t? nevojiten, si dhe p?r t? mbledhur komente dhe sugjerime nga stafi dhe vullnetar?t e organizat?s. Kryerja e nj? praktike t? till? ?sht? shum? e k?shillueshme t? zhvillohet.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:55.365Z",
"created_at":"2021-11-22T13:59:19.528Z",
"updated_at":"2021-12-06T09:54:26.199Z"
},
"organization_evaluation":null,
"questOptionId":49,
"sort":1
},
{
"id":50,
"question":13,
"description":"Organizata jon? kryen vler?sime periodike t? performanc?s t? punonj?sve por jo sipas nj? planifikimi dhe procedure t? formalizuar.",
"points":2,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:19:36.859Z",
"created_at":"2021-06-10T14:19:30.174Z",
"updated_at":"2021-12-06T09:54:43.753Z",
"question_option_suggestion":{
"id":59,
"question_option":50,
"description":"Vler?simi i performanc?s s? burimeve njer?zore ?sht? nj? aspekt shum? i r?nd?sish?m p?r t? analizuar ecurin? e organizat?s, rregullimet e mundshme q? mund t? nevojiten, si dhe p?r t? mbledhur komente dhe sugjerime nga stafi dhe vullnetar?t e organizat?s. Kryerja e nj? praktike t? till? ?sht? shum? e k?shillueshme t? zhvillohet, sipas nj? procedure t? formalizuar n? m?nyr? periodike.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:59.427Z",
"created_at":"2021-11-22T13:59:50.511Z",
"updated_at":"2021-12-06T09:54:43.755Z"
},
"organization_evaluation":null,
"questOptionId":50,
"sort":2
},
{
"id":52,
"question":13,
"description":"Vler?simi i performanc?s s? punonj?sve b?het periodikisht me afate t? p?rcaktuara, , p?rmes nj? procedure t? formalizuar me p?rfshirjen dhe vler?simin e punonj?sit dhe t? gjitha niveleve hirearkike.",
"points":4,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:20:57.838Z",
"created_at":"2021-06-10T14:20:54.741Z",
"updated_at":"2021-12-06T09:55:18.506Z",
"question_option_suggestion":{
"id":61,
"question_option":52,
"description":"Vler?simi periodik i performanc?s s? punonj?sve, n?p?rmjet nj? procedure t? formalizuar dhe me p?rfshirjen e t? gjitha niveleve hierarkike, ?sht? nj? praktik? e mir? institucionale. ?sht? e r?nd?sishme q? k?to praktika t? zhvillohen m? tej dhe m?simet e nxjerra gjat? ngritjes s? tyre t? ndahen, k?shtu q? organizatat e tjera mund t? ndjekin k?t? shembull.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:21:08.716Z",
"created_at":"2021-11-22T14:03:21.740Z",
"updated_at":"2021-12-06T09:55:18.508Z"
},
"organization_evaluation":null,
"questOptionId":52,
"sort":4
}
],
"commitments":[
{
"id":6,
"name":"Burime Njer?zore t? Mir? Menaxhuara",
"icon":"fa-pencil",
"primary_color":"#03BEE7",
"secondary_color":"#428D9D",
"active":true,
"published_at":"2021-05-13T08:10:12.178Z",
"created_at":"2021-05-13T08:10:08.282Z",
"updated_at":"2021-07-26T10:25:12.028Z",
"icon_color":"#027A95",
"locale":"sq",
"commitments_icon":6,
"commitment_icon":6,
"color_palette":"dark_blue",
"link":"/managed-human-resources",
"sortId":7
}
]
}
]
這是資料的json格式
uj5u.com熱心網友回復:
假設服務器回傳此回應:
[
{
"id":11,
"description":"A ka organizata juaj politika dhe procedura t? brendshme organizative si pjes? e t? cilave parashikohet qart? m?nyra e ngritjes s? fondeve dhe e manaxhimit t? tyre n? m?nyr? etike?",
"active":true,
"sortId":11,
"locale":"sq",
"published_at":"2021-06-10T13:56:39.618Z",
"created_at":"2021-06-10T13:56:36.456Z",
"updated_at":"2021-10-06T09:18:29.403Z",
"organization_evaluation":null,
"questId":11,
"question_options":[
{
"id":44,
"question":11,
"description":"Organizata ka politika dhe procedura t? brendshme organizative si pjes? e t? cilave parashikohet shum? qart? m?nyra e ngritjes s? fondeve dhe e manaxhimit t? tyre n? m?nyr? etike.",
"points":4,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:15:34.685Z",
"created_at":"2021-06-10T14:15:31.675Z",
"updated_at":"2021-12-06T09:53:00.315Z",
"question_option_suggestion":{
"id":53,
"question_option":44,
"description":"Kjo ?sht? nj? praktik? shum? e mir? p?r mund?simin e qendrueshm?ris? organizative dhe transparenc?n e llogaridh?nien m? t? gjith? grupet e interesit. ?sht? e r?nd?sishme q? k?to procese t? mbahen dhe m?simet e nxjerra t? ndahen, n? m?nyr? q? organizatat e tjera t? mund t? ndjekin k?t? shembull. ",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:34.873Z",
"created_at":"2021-11-22T13:55:53.026Z",
"updated_at":"2021-12-06T09:53:00.317Z"
},
"organization_evaluation":null,
"questOptionId":44,
"sort":4
},
{
"id":41,
"question":11,
"description":"Organizata nuk ka politika dhe procedura t? tilla.",
"points":1,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:13:20.937Z",
"created_at":"2021-06-10T14:13:17.713Z",
"updated_at":"2021-12-06T09:51:40.886Z",
"question_option_suggestion":{
"id":50,
"question_option":41,
"description":"T? paturit e praktikave t? qarta dhe t? formalizuara p?r mbledhjen e fondeve dhe p?rdorimin e menaxhimin etik t? tyre, ?sht? nj? praktik? e k?shillueshme pasi p?rb?n nj? mjet p?r rritjen e qendruesh?mris? s? organizat?s, uljen e var?sis? nga nj? burim i caktuar fondesh, dhe krijimin e mund?sis? p?r t? qen? novator e i suksessh?m. Gjithashtu k?to praktika garantojn? njohjen gjer?sisht t? burimeve nga t? gjitha pal?t e interesuara. Kjo do t? sjell? m? shum? transparenc? dhe t? p?rmir?soj? p?rgjegjshm?rin?.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:22.267Z",
"created_at":"2021-11-22T13:54:07.049Z",
"updated_at":"2021-12-06T09:51:40.889Z"
},
"organization_evaluation":null,
"questOptionId":41,
"sort":1
},
{
"id":42,
"question":11,
"description":"Organizata nuk ka politika dhe procedura t? tilla por ndjek disa parime t? p?rgjithshme etike n? ngritjen e fondeve dhe manaxhimin e tyre.",
"points":2,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:13:57.687Z",
"created_at":"2021-06-10T14:13:49.677Z",
"updated_at":"2021-12-06T09:52:12.383Z",
"question_option_suggestion":{
"id":51,
"question_option":42,
"description":"T? paturit e praktikave t? qarta dhe t? formalizuara p?r mbledhjen e fondeve dhe p?rdorimin e menaxhimin etik t? tyre, ?sht? nj? praktik? e k?shillueshme pasi p?rb?n nj? mjet p?r rritjen e qendruesh?mris? s? organizat?s, uljen e var?sis? nga nj? burim i caktuar fondesh, dhe krijimin e mund?sis? p?r t? qen? novator e i suksessh?m. Gjithashtu k?to praktika garantojn? njohjen gjer?sisht t? burimeve nga t? gjitha pal?t e interesuara. Kjo do t? sjell? m? shum? transparenc? dhe t? p?rmir?soj? p?rgjegjshm?rin?.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:26.501Z",
"created_at":"2021-11-22T13:54:46.944Z",
"updated_at":"2021-12-06T09:52:12.385Z"
},
"organization_evaluation":null,
"questOptionId":42,
"sort":2
},
{
"id":43,
"question":11,
"description":"Organizata ka politika dhe procedura t? brendshme organizative si pjes? e t? cilave ka parashikime t? p?rgjithshme mbi m?nyr?n e ngritjes s? fondeve.",
"points":3,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:14:54.428Z",
"created_at":"2021-06-10T14:14:51.561Z",
"updated_at":"2021-12-06T09:52:39.514Z",
"question_option_suggestion":{
"id":52,
"question_option":43,
"description":"Zhvillimi dhe p?rdit?simi i vazhduesh?m i praktikave t? tilla, n? var?si dhe t? dinamikave zhvillimore t? organizat?s, siguron nj? p?rqasje novatore lidhur me garantimin e qendrueshm?ris? s? organizat?s. K?shillohet q? k?to politika t? jen? t? mir? detajuara, duke mund?suar jo vet?m nj? njohje sa m? t? gjer? nga t? gjith? grupet e interesit n? kuad?r t? transparenc?s dhe llogaridh?nies, por dhe zbatim t? sakt? t? tyre n? t? gjith? nivelet hirarkike.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:31.381Z",
"created_at":"2021-11-22T13:55:27.990Z",
"updated_at":"2021-12-06T09:52:39.518Z"
},
"organization_evaluation":null,
"questOptionId":43,
"sort":3
}
],
"commitments":[
{
"id":5,
"name":"Financim, Ngritje Fondesh dhe Manaxhim i Burimeve",
"icon":"fa-pencil",
"primary_color":"#348D73",
"secondary_color":"#06C088",
"active":true,
"published_at":"2021-05-13T08:09:20.077Z",
"created_at":"2021-05-13T08:09:11.107Z",
"updated_at":"2021-07-26T10:25:26.204Z",
"icon_color":"#33D0A1",
"locale":"sq",
"commitments_icon":5,
"commitment_icon":5,
"color_palette":"light_blue",
"link":"/financing",
"sortId":3
}
]
},
{
"id":13,
"description":"A kryen organizata juaj vler?sime periodike t? performanc?s t? punonj?sve dhe si? ",
"active":true,
"sortId":13,
"locale":"sq",
"published_at":"2021-06-10T13:57:37.862Z",
"created_at":"2021-06-10T13:57:34.723Z",
"updated_at":"2021-10-06T09:18:57.834Z",
"organization_evaluation":null,
"questId":13,
"question_options":[
{
"id":51,
"question":13,
"description":"Vler?simi i performanc?s s? punonj?sve b?het periodikisht me afate t? p?rcaktuara, , p?rmes nj? procedure t? formalizuar, por vet?m nga drejtuesi i organizat?s.",
"points":3,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:20:35.874Z",
"created_at":"2021-06-10T14:19:48.983Z",
"updated_at":"2021-12-06T09:55:01.718Z",
"question_option_suggestion":{
"id":60,
"question_option":51,
"description":"Kjo ?sht? nj? praktik? e mir? organizative e cila mund t? p?rmir?sohet m? tej me p?rfshirjen n? procedur? jo vet?m t? drejtuesit t? organizat?s por dhe niveleve t? tjera t? hierarkis?. Kjo p?rfshirje ofron nj? k?ndv?shtrim m? t? gjer? t? vler?simit t? p?rformanc?s n? raport dhe me pjes?n tjet?r t? stafit kryesisht supervizues. ",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:21:05.079Z",
"created_at":"2021-11-22T14:02:42.810Z",
"updated_at":"2021-12-06T09:55:01.724Z"
},
"organization_evaluation":null,
"questOptionId":51,
"sort":3
},
{
"id":49,
"question":13,
"description":"Organizata jon? nuk kryen vler?sime periodike t? performanc?s s? punonj?sve.",
"points":1,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:19:03.812Z",
"created_at":"2021-06-10T14:18:56.048Z",
"updated_at":"2021-12-06T09:54:26.197Z",
"question_option_suggestion":{
"id":58,
"question_option":49,
"description":"Vler?simi i performanc?s s? burimeve njer?zore ?sht? nj? aspekt shum? i r?nd?sish?m p?r t? analizuar ecurin? e organizat?s, rregullimet e mundshme q? mund t? nevojiten, si dhe p?r t? mbledhur komente dhe sugjerime nga stafi dhe vullnetar?t e organizat?s. Kryerja e nj? praktike t? till? ?sht? shum? e k?shillueshme t? zhvillohet.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:55.365Z",
"created_at":"2021-11-22T13:59:19.528Z",
"updated_at":"2021-12-06T09:54:26.199Z"
},
"organization_evaluation":null,
"questOptionId":49,
"sort":1
},
{
"id":50,
"question":13,
"description":"Organizata jon? kryen vler?sime periodike t? performanc?s t? punonj?sve por jo sipas nj? planifikimi dhe procedure t? formalizuar.",
"points":2,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:19:36.859Z",
"created_at":"2021-06-10T14:19:30.174Z",
"updated_at":"2021-12-06T09:54:43.753Z",
"question_option_suggestion":{
"id":59,
"question_option":50,
"description":"Vler?simi i performanc?s s? burimeve njer?zore ?sht? nj? aspekt shum? i r?nd?sish?m p?r t? analizuar ecurin? e organizat?s, rregullimet e mundshme q? mund t? nevojiten, si dhe p?r t? mbledhur komente dhe sugjerime nga stafi dhe vullnetar?t e organizat?s. Kryerja e nj? praktike t? till? ?sht? shum? e k?shillueshme t? zhvillohet, sipas nj? procedure t? formalizuar n? m?nyr? periodike.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:20:59.427Z",
"created_at":"2021-11-22T13:59:50.511Z",
"updated_at":"2021-12-06T09:54:43.755Z"
},
"organization_evaluation":null,
"questOptionId":50,
"sort":2
},
{
"id":52,
"question":13,
"description":"Vler?simi i performanc?s s? punonj?sve b?het periodikisht me afate t? p?rcaktuara, , p?rmes nj? procedure t? formalizuar me p?rfshirjen dhe vler?simin e punonj?sit dhe t? gjitha niveleve hirearkike.",
"points":4,
"active":true,
"icon":null,
"locale":"sq",
"published_at":"2021-06-10T14:20:57.838Z",
"created_at":"2021-06-10T14:20:54.741Z",
"updated_at":"2021-12-06T09:55:18.506Z",
"question_option_suggestion":{
"id":61,
"question_option":52,
"description":"Vler?simi periodik i performanc?s s? punonj?sve, n?p?rmjet nj? procedure t? formalizuar dhe me p?rfshirjen e t? gjitha niveleve hierarkike, ?sht? nj? praktik? e mir? institucionale. ?sht? e r?nd?sishme q? k?to praktika t? zhvillohen m? tej dhe m?simet e nxjerra gjat? ngritjes s? tyre t? ndahen, k?shtu q? organizatat e tjera mund t? ndjekin k?t? shembull.",
"active":true,
"locale":"sq",
"published_at":"2021-11-24T13:21:08.716Z",
"created_at":"2021-11-22T14:03:21.740Z",
"updated_at":"2021-12-06T09:55:18.508Z"
},
"organization_evaluation":null,
"questOptionId":52,
"sort":4
}
],
"commitments":[
{
"id":6,
"name":"Burime Njer?zore t? Mir? Menaxhuara",
"icon":"fa-pencil",
"primary_color":"#03BEE7",
"secondary_color":"#428D9D",
"active":true,
"published_at":"2021-05-13T08:10:12.178Z",
"created_at":"2021-05-13T08:10:08.282Z",
"updated_at":"2021-07-26T10:25:12.028Z",
"icon_color":"#027A95",
"locale":"sq",
"commitments_icon":6,
"commitment_icon":6,
"color_palette":"dark_blue",
"link":"/managed-human-resources",
"sortId":7
}
]
}
]
我們需要根據問題構建新的選定選項陣列。
import React, {useState} from 'react'
import {View,FlatList,StyleSheet,Text} from 'react-native'
import {RadioButton} from "react-native-paper"
const has = require('lodash.has');
import response from './response'
const styles = StyleSheet.create({})
const Step3 = () => {
const [questions, setQuestions] = useState(response);
const [answers,setAnswers] = useState({})
const [values, setValue] = useState()
const isOptionSelected = (option)=>{
const answer = answers[option.question]
if(answer){
return option.id == answer.id
}
return false
}
const OptionList = (groupOption) => {
return (
<FlatList
data={groupOption.options}
keyExtractor={(result) => result.id.toString()}
renderItem={({ item, index}) => {
const clickedRadio = () => {
const selectedOption = {[item.question]:{...item}}
setAnswers({...answers,...selectedOption})
console.log({answers})
}
const status = isOptionSelected(item)? 'checked' : 'unchecked'
return (
<View key={index}>
<RadioButton status={status} onPress={clickedRadio} label={item.description} onChange={()=> clickedRadio() } />
</View>
);
}}
/>
);
};
return (
<View style={styles.container}>
<Text style={{ fontWeight: "bold", fontSize: 16, color: "#6B24AA" }}>
Choose an option/Scroll for more questions
</Text>
<FlatList
data={questions}
keyExtractor={(result) => result.id.toString()}
renderItem={({ item, index }) => {
return (
<View style={styles.groupOptions} key={index}>
<Text>{item.description}</Text>
<OptionList options={item?.question_options}></OptionList>
</View>
);
}}
/>
</View>
)
}
export default Step3
為簡單起見,我洗掉了從服務器獲取資料的邏輯。
在此處檢查作業示例
https://snack.expo.dev/@emmbyiringiro/1376bf
uj5u.com熱心網友回復:
您需要為每個選項組選擇值,這可以通過使用初始值狀態的物件來實作:
const [values, setValue] = useState({})
然后更新 OptionsList 道具以接受另外兩個道具,onSelect 和 isSelected。
<OptionList options={item?.question_options} selectedId={value[item?.id]} onSelect={(optionId)=>{ setValue(prevValues=>({...prevValues, [item?.id]:optionId})) }}/>
在 OptionList 組件中,您需要使用selectedIdfrom props為活動選項添加特定樣式item.id===selectedId,并且在選擇時,您將onSelect使用選項 Id 作為引數呼叫道具。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/403677.html
標籤:
