【发布时间】:2021-01-25 02:49:34
【问题描述】:
我有一个应用程序,它将创建一个食谱数据库,用户将在其中输入他拥有的成分,并且该应用程序应该返回用户输入的这种组合可用的食谱。
一旦我拥有包含许多键/值信息的配方对象:
const [recipes, setRecipes] = useState([
{ id: 1, easyOfPrepare: 'facil', author: 'www.', category: 'Salgada', type: 'Prato principal', name: 'pão de forma', key: '1', ingredients: ['sal', 'ovo', 'mantega', 'maionese', 'farinha'] },
{ id: 2, easyOfPrepare: 'facil', author: 'www.', category: 'Salgada', type: 'Entrada', name: 'macarrao ao molho branco', key: '2', ingredients: ['macarrao', 'oleo', 'creme de leite'] },
{ id: 3, easyOfPrepare: 'facil', author: 'www.', category: 'Salgada', type: 'Salada', name: 'Arroz marroquino', key: '3', ingredients: ['A', 'B', 'C'] },
{ id: 4, easyOfPrepare: 'facil', author: 'www.', category: 'Doce', type: 'Sobremesa', name: 'Bolo', key: '4', ingredients: ['farinha', 'açucar', 'etc'] },
{ id: 5, easyOfPrepare: 'facil', author: 'www.', category: 'Doce', type: 'Bolo', name: 'doce de leite', key: '5', ingredients: ['AA', 'BB', 'CC'] },
])
用户输入保存在另一个对象中
const [ingredients, setIngredients] = useState(['farinha', 'ovos', 'leite'])
const addIngredients = e => {
e.preventDefault();
setIngredients(prevIngredient => [...prevIngredient, name]);
}
一旦用户通知了预期的成分,就会调用这个添加成分。
一旦用户输入了以下组合:“sal”、“ovo”、“mantega”、“maionese”、“farinha”,我如何根据食谱过滤这些成分以定义唯一可能的成分组合是第一个?
谢谢!
【问题讨论】:
标签: javascript node.js reactjs react-native