- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我这里有一个数据:
import Category from '../models/category';
import Meal from '../models/meal';
export const CATEGORIES = [
new Category('c1', 'Italian', '#f5428d'),
new Category('c2', 'Quick & Easy', '#f54242'),
new Category('c3', 'Hamburgers', '#f5a442'),
new Category('c4', 'German', '#f5d142'),
new Category('c5', 'Light & Lovely', '#368dff'),
new Category('c6', 'Exotic', '#41d95d'),
new Category('c7', 'Breakfast', '#9eecff'),
new Category('c8', 'Asian', '#b9ffb0'),
new Category('c9', 'French', '#ffc7ff'),
new Category('c10', 'Summer', '#47fced')
];
export const MEALS = [
new Meal(
'm1',
['c1', 'c2'],
'Spaghetti with Tomato Sauce',
'affordable',
'simple',
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
20,
[
'4 Tomatoes',
'1 Tablespoon of Olive Oil',
'1 Onion',
'250g Spaghetti',
'Spices',
'Cheese (optional)'
],
[
'Cut the tomatoes and the onion into small pieces.',
'Boil some water - add salt to it once it boils.',
'Put the spaghetti into the boiling water - they should be done in about 10 to 12 minutes.',
'In the meantime, heaten up some olive oil and add the cut onion.',
'After 2 minutes, add the tomato pieces, salt, pepper and your other spices.',
'The sauce will be done once the spaghetti are.',
'Feel free to add some cheese on top of the finished dish.'
],
false,
true,
true,
true
),
new Meal(
'm2',
['c2'],
'Toast Hawaii',
'affordable',
'simple',
'https://cdn.pixabay.com/photo/2018/07/11/21/51/toast-3532016_1280.jpg',
10,
[
'1 Slice White Bread',
'1 Slice Ham',
'1 Slice Pineapple',
'1-2 Slices of Cheese',
'Butter'
],
[
'Butter one side of the white bread',
'Layer ham, the pineapple and cheese on the white bread',
'Bake the toast for round about 10 minutes in the oven at 200°C'
],
false,
false,
false,
false
),
new Meal(
'm3',
['c3'],
'Classic Hamburger',
'pricey',
'simple',
'https://cdn.pixabay.com/photo/2014/10/23/18/05/burger-500054_1280.jpg',
45,
[
'300g Cattle Hack',
'1 Tomato',
'1 Cucumber',
'1 Onion',
'Ketchup',
'2 Burger Buns'
],
[
'Form 2 patties',
'Fry the patties for c. 4 minutes on each side',
'Quickly fry the buns for c. 1 minute on each side',
'Bruch buns with ketchup',
'Serve burger with tomato, cucumber and onion'
],
false,
false,
false,
true
),
new Meal(
'm4',
['c4'],
'Wiener Schnitzel',
'luxurious',
'challenging',
'https://cdn.pixabay.com/photo/2018/03/31/19/29/schnitzel-3279045_1280.jpg',
60,
[
'8 Veal Cutlets',
'4 Eggs',
'200g Bread Crumbs',
'100g Flour',
'300ml Butter',
'100g Vegetable Oil',
'Salt',
'Lemon Slices'
],
[
'Tenderize the veal to about 2–4mm, and salt on both sides.',
'On a flat plate, stir the eggs briefly with a fork.',
'Lightly coat the cutlets in flour then dip into the egg, and finally, coat in breadcrumbs.',
'Heat the butter and oil in a large pan (allow the fat to get very hot) and fry the schnitzels until golden brown on both sides.',
'Make sure to toss the pan regularly so that the schnitzels are surrounded by oil and the crumbing becomes ‘fluffy’.',
'Remove, and drain on kitchen paper. Fry the parsley in the remaining oil and drain.',
'Place the schnitzels on awarmed plate and serve garnishedwith parsley and slices of lemon.'
],
false,
false,
false,
false
),
new Meal(
'm5',
['c2', 'c5', 'c10'],
'Salad with Smoked Salmon',
'luxurious',
'simple',
'https://cdn.pixabay.com/photo/2016/10/25/13/29/smoked-salmon-salad-1768890_1280.jpg',
15,
[
'Arugula',
"Lamb's Lettuce",
'Parsley',
'Fennel',
'200g Smoked Salmon',
'Mustard',
'Balsamic Vinegar',
'Olive Oil',
'Salt and Pepper'
],
[
'Wash and cut salad and herbs',
'Dice the salmon',
'Process mustard, vinegar and olive oil into a dessing',
'Prepare the salad',
'Add salmon cubes and dressing'
],
true,
false,
true,
true
),
new Meal(
'm6',
['c6', 'c10'],
'Delicious Orange Mousse',
'affordable',
'hard',
'https://cdn.pixabay.com/photo/2017/05/01/05/18/pastry-2274750_1280.jpg',
240,
[
'4 Sheets of Gelatine',
'150ml Orange Juice',
'80g Sugar',
'300g Yoghurt',
'200g Cream',
'Orange Peel'
],
[
'Dissolve gelatine in pot',
'Add orange juice and sugar',
'Take pot off the stove',
'Add 2 tablespoons of yoghurt',
'Stir gelatin under remaining yoghurt',
'Cool everything down in the refrigerator',
'Whip the cream and lift it under die orange mass',
'Cool down again for at least 4 hours',
'Serve with orange peel'
],
true,
false,
true,
false
),
new Meal(
'm7',
['c7'],
'Pancakes',
'affordable',
'simple',
'https://cdn.pixabay.com/photo/2018/07/10/21/23/pancake-3529653_1280.jpg',
20,
[
'1 1/2 Cups all-purpose Flour',
'3 1/2 Teaspoons Baking Powder',
'1 Teaspoon Salt',
'1 Tablespoon White Sugar',
'1 1/4 cups Milk',
'1 Egg',
'3 Tablespoons Butter, melted'
],
[
'In a large bowl, sift together the flour, baking powder, salt and sugar.',
'Make a well in the center and pour in the milk, egg and melted butter; mix until smooth.',
'Heat a lightly oiled griddle or frying pan over medium high heat.',
'Pour or scoop the batter onto the griddle, using approximately 1/4 cup for each pancake. Brown on both sides and serve hot.'
],
true,
false,
true,
false
),
new Meal(
'm8',
['c8'],
'Creamy Indian Chicken Curry',
'pricey',
'challenging',
'https://cdn.pixabay.com/photo/2018/06/18/16/05/indian-food-3482749_1280.jpg',
35,
[
'4 Chicken Breasts',
'1 Onion',
'2 Cloves of Garlic',
'1 Piece of Ginger',
'4 Tablespoons Almonds',
'1 Teaspoon Cayenne Pepper',
'500ml Coconut Milk'
],
[
'Slice and fry the chicken breast',
'Process onion, garlic and ginger into paste and sauté everything',
'Add spices and stir fry',
'Add chicken breast + 250ml of water and cook everything for 10 minutes',
'Add coconut milk',
'Serve with rice'
],
true,
false,
false,
true
),
new Meal(
'm9',
['c9'],
'Chocolate Souffle',
'affordable',
'hard',
'https://cdn.pixabay.com/photo/2014/08/07/21/07/souffle-412785_1280.jpg',
45,
[
'1 Teaspoon melted Butter',
'2 Tablespoons white Sugar',
'2 Ounces 70% dark Chocolate, broken into pieces',
'1 Tablespoon Butter',
'1 Tablespoon all-purpose Flour',
'4 1/3 tablespoons cold Milk',
'1 Pinch Salt',
'1 Pinch Cayenne Pepper',
'1 Large Egg Yolk',
'2 Large Egg Whites',
'1 Pinch Cream of Tartar',
'1 Tablespoon white Sugar'
],
[
'Preheat oven to 190°C. Line a rimmed baking sheet with parchment paper.',
'Brush bottom and sides of 2 ramekins lightly with 1 teaspoon melted butter; cover bottom and sides right up to the rim.',
'Add 1 tablespoon white sugar to ramekins. Rotate ramekins until sugar coats all surfaces.',
'Place chocolate pieces in a metal mixing bowl.',
'Place bowl over a pan of about 3 cups hot water over low heat.',
'Melt 1 tablespoon butter in a skillet over medium heat. Sprinkle in flour. Whisk until flour is incorporated into butter and mixture thickens.',
'Whisk in cold milk until mixture becomes smooth and thickens. Transfer mixture to bowl with melted chocolate.',
'Add salt and cayenne pepper. Mix together thoroughly. Add egg yolk and mix to combine.',
'Leave bowl above the hot (not simmering) water to keep chocolate warm while you whip the egg whites.',
'Place 2 egg whites in a mixing bowl; add cream of tartar. Whisk until mixture begins to thicken and a drizzle from the whisk stays on the surface about 1 second before disappearing into the mix.',
'Add 1/3 of sugar and whisk in. Whisk in a bit more sugar about 15 seconds.',
'whisk in the rest of the sugar. Continue whisking until mixture is about as thick as shaving cream and holds soft peaks, 3 to 5 minutes.',
'Transfer a little less than half of egg whites to chocolate.',
'Mix until egg whites are thoroughly incorporated into the chocolate.',
'Add the rest of the egg whites; gently fold into the chocolate with a spatula, lifting from the bottom and folding over.',
'Stop mixing after the egg white disappears. Divide mixture between 2 prepared ramekins. Place ramekins on prepared baking sheet.',
'Bake in preheated oven until scuffles are puffed and have risen above the top of the rims, 12 to 15 minutes.'
],
true,
false,
true,
false
),
new Meal(
'm10',
['c2', 'c5', 'c10'],
'Asparagus Salad with Cherry Tomatoes',
'luxurious',
'simple',
'https://cdn.pixabay.com/photo/2018/04/09/18/26/asparagus-3304997_1280.jpg',
30,
[
'White and Green Asparagus',
'30g Pine Nuts',
'300g Cherry Tomatoes',
'Salad',
'Salt, Pepper and Olive Oil'
],
[
'Wash, peel and cut the asparagus',
'Cook in salted water',
'Salt and pepper the asparagus',
'Roast the pine nuts',
'Halve the tomatoes',
'Mix with asparagus, salad and dressing',
'Serve with Baguette'
],
true,
true,
true,
true
)
];
然后我的老师尝试使用 ff 代码提取它:
const catId = props.route.params.categoryId;
const displayMeals = MEALS.filter(meal => meal.categoryIds.indexOf(catId) >= 0);
这部分是我的绊脚石:
const displayMeals = MEALS.filter(meal => meal.categoryIds.indexOf(catId) >= 0);
虽然我知道过滤器返回一个基于
meal.categoryIds.indexOf(catId)
的新数组我不明白为什么我们需要
>=0
.
最佳答案
更现代的方式是写 meal.categories.includes(catId)
.当数组 meal.categories
为真包括 catId
的值,否则为假。
你的代码显然是以前的 includes
可用并使用 indexOf
做同样的事情.indexOf
返回给定元素在 array1 中的索引。如果未找到,则返回 -1
.因此,如果结果是 >= 0
,应该是被发现了。 (您也可以查看 != -1
。)
例如:
const array = ['a', 'c', 'b']
console.log(array.indexOf('a')) // 0
console.log(array.indexOf('b')) // 2
console.log(array.indexOf('c')) // 1
console.log(array.indexOf('x')) // -1
关于Javascript indexOf >= 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62952733/
我想检索字符串列表中的行号(从文件加载)。Indexof 似乎完全匹配。有没有办法检索带有通配符版本的 Indexof 的行?类似于 SL.Indexof('?sometext')? 谢谢! 最佳答案
我已经解析了一些 JSON,但我想获取从 JSON 获得的链接,在链接中找到一个使其不同的标识符(例如 www.foo.com/IDENTIFIER/home),并拥有该标识符作为一个字符串插入到另一
我正在浏览 jQuery 的源代码并碰到这个: return indexOf.call( array, elem ); - Line 683 我想知道这背后的逻辑是什么,为什么不这样做: return
我正在从一个带有空格后的非组合变音符号的字符串中创建一个子字符串。这样做时,我使用 .Contains() 检查字符串。然后执行子串。当我使用空格时 char内部 .IndexOf() ,程序按预期执
我正在使用 Jayway JsonPath 库版本 2.4.0。在 jsonPath 中使用 indexOf 函数,例如。 $.values[?(@.num.indexOf('101') != -1)
由于某种原因,GWT 模拟(客户端)jdk 方法 indexOf() 无法按预期工作。 示例:. 我有一个包含 3 个 NaN 对象的列表: List doubleList = new ArrayLi
Resharper 推荐我使用: int notesFirstSpaceIndex = notes.IndexOf(" ", StringComparison.Ordinal); 代替: int no
我想 String.indexOf(char)比String.indexOf(String)使用单个字符和单个字符串时(例如,'x' & "x") 为了确保我的猜测,我编写了如下简单的测试代码。 pu
我在 IE 8 中的数组顶部使用了 indexOf 方法,但它给出了错误(因为不支持它)。我选择使用 underscore.js 库。我用了_.indexOf(array, value, [isSor
这个问题已经有答案了: No overload for method, takes 0 arguments? (1 个回答) 已关闭 7 年前。 我似乎无法弄清楚为什么我总是收到此错误。 No ove
在 Firefox 和 Opera 上使用 Javascript 调用 indexOf 时出错。在 IE 中工作正常。 错误信息如下: 行动 function anonymous(Grid, Row,
在第一次渲染Use Effect时遇到一个特定的错误,我不确定如何解决。我认为这与该功能的异步性有关,但不确定。项目是一个Reactjs,Firebase,FiRestore Todo应用程序,根据用
在第一次渲染Use Effect时遇到一个特定的错误,我不确定如何解决。我认为这与该功能的异步性有关,但不确定。项目是一个Reactjs,Firebase,FiRestore Todo应用程序,根据用
我需要创建一个对字符串进行排序的函数。字符串中的每个单词都将包含一个数字。数字可以是 1 到 9(不能是 0)。 例如输入:“is2 Thi1s T4est 3a”,函数应返回“Thi1s is2 3
有没有一种方法可以在 Java 中使用 indexOf 在单个解析中查找给定文本中多个字符串的位置? 例如,我想在一次文本解析中为“你”和“ session ”做一个 indexOf“你今天能参加 s
我正在使用以下代码来搜索字符串中的值。 if (myValue.indexOf("Call") > -1) { //dosomething } 我该怎么做和或? (myValue.indexOf("
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
This question already has an answer here: Reference - What does this regex mean? (1 个回答) 1年前关闭。 我必须在
我把它写进了一个 REPL: case class Thingy(s: String) val things = List(Thingy("x"), Thingy("y")) things.index
在带有此查询的 JMESPath 中: people[].{"index":@.index,"name":name, "state":state.name} 在此示例数据上: { "people"
我是一名优秀的程序员,十分优秀!