2016-08-29 2 views
0

안녕하세요, 내 UI에 표시하려는 데이터가 있습니다. 나는 리튬의JSX에서 데이터를 반복하는 방법

내가 주변에 내 머리를 정리하지 못할 jsx

내부 루프 수 있도록하고 싶습니다

, 너희들이 내게 줄 수에 ProductTypeID 및 ProductTypeName의 데이터를 시도하고 표시 루프를 할 수 있도록하려면 힌트? 나는 데이터를 다루는 것이 좋지 않고 tru를 반복한다.

[{ 
    "ProductTypeID": 14, 
    "ProductTypeName": "ItemName1", 
    "ProductTypeImageUrl": "", 
    "ProductTypeThumbUrl": "", 
    "ProductTypeIconUrl": "", 
    "IsActive": 1, 
    "ProductTypeBlueImage": null, 
    "Is3HourRent": null 
}, { 
    "ProductTypeID": 1, 
    "ProductTypeName": ItemName2", 
    "ProductTypeImageUrl": "", 
    "ProductTypeThumbUrl": "", 
    "ProductTypeIconUrl": "", 
    "IsActive": 1, 
    "ProductTypeBlueImage": null, 
    "Is3HourRent": false 
}, { 
    "ProductTypeID": 10, 
    "ProductTypeName": "ItemName3", 
    "ProductTypeImageUrl": "", 
    "ProductTypeThumbUrl": "", 
    "ProductTypeIconUrl": "", 
    "IsActive": 1, 
    "ProductTypeBlueImage": null, 
    "Is3HourRent": true 
}] 

답변

1
render() { 
var data = [{ 
    'ProductTypeID': 14, 
    'ProductTypeName': 'ItemName1' 
}, 
{ 
    'ProductTypeID': 15, 
    'ProductTypeName': 'ItemName2' 
}]; 

return (<ul> 
    {data.map((item) => { 
    return (<li key={item.ProductTypeID}> 
    <span>ID: {item.ProductTypeID}</span> 
    <span>Name: {item.ProductTypeName}</span> 
    </li>); 
    })} 
</ul>); 
} 
+0

두 답변이 모두 정확하고 JSX의 실제 데이터를 매핑하는 방법을 이해하는 데 도움이되었습니다. 감사합니다. Alexey Pedyashev – user1780729

1

당신은 map를 사용하여 렌더링 방법 같은 것을 할 수 있습니다.

render(){ 
    return <ul> 
     {data.map(item => <li key={item.ProductTypeID}>{item.ProductTypeID}</li>)} 
     </ul> 
} 
+0

두 답변이 모두 정확하고 JSX의 실제 데이터를 매핑하는 방법을 이해하는 데 도움이되었습니다. 고마워요. – user1780729

+0

사용법이나 화살표 기능 때문에 대답이 조금 더 마음에 드네요. – user1780729

관련 문제