在React世界中令人沮丧的时候......我需要能够根据某些标准创建标记.例如,我收到一系列项目.我需要检查这些项目,并根据标准,我需要生成不同的标记.例如,我有一个函数接收一个项目数组:
processItems(itemArray) {
// Create an empty array that will hold the final JSX output.
let buffer = []
// Somehow push the first required markup into the buffer.
buffer.push(<div className"container flex center">);
// ... here we do a switch statement that evaluates each item in the 'itemArray' argument and based on that I create different <div className="XYZ">{...put stuff here...}</div> markup, which I will push into the buffer - which will contain the final JSX output...
// Now I close …Run Code Online (Sandbox Code Playgroud) 我在Swift中有一个数组(items)和一个字典数组(数据):
let items = [2, 6, 4]
var data = [
["id": "1", "title": "Leslie", "color": "brown"],
["id": "8", "title": "Mary", "color": "red"],
["id": "6", "title": "Joe", "color": "blue"],
["id": "2", "title": "Paul", "color": "gray"],
["id": "5", "title": "Stephanie", "color": "pink"],
["id": "9", "title": "Steve", "color": "purple"],
["id": "3", "title": "Doug", "color": "violet"],
["id": "4", "title": "Ken", "color": "white"],
["id": "7", "title": "Annie", "color": "black"]
]
Run Code Online (Sandbox Code Playgroud)
我想创建一个包含字典数组的数组,其"id"等于'items'数组中提供的数字.阿卡我想最终得到一个阵列:
var result = [
["id": "6", "title": "Joe", "color": "blue"],
["id": "2", "title": …Run Code Online (Sandbox Code Playgroud)