return
прерывает функцию. То есть у тебя происходит только одна итерация цикла, и затем выход из функции. Собери itemPrice[0] в список объявленный вне цикла (result.append(itemPrice[0]))
и верни result вне цикла.
Имей ввиду то что ты в своей имплементации объявил itemPrice
вне цикла и это имеет 0 эффекта, так как при каждой итерации у тебя создается новый объект, например вот здесь itemPrice = i.find(...
Over the last several years we’ve seen a whole range of ideas regarding the architecture of systems. These include:
Hexagonal Architecture (a.k.a. Ports and Adapters) by Alistair Cockburn and adopted by Steve Freeman, and Nat Pryce in their wonderful book Growing Object Oriented Software
Onion Architecture by Jeffrey Palermo
Screaming Architecture from a blog of mine last year
DCI from James Coplien, and Trygve Reenskaug.
BCE by Ivar Jacobson from his book Object Oriented Software Engineering: A Use-Case Driven Approach
Объект менять не нужно.
const SERIES = [
{
comment: '1 сезон',
folder: [
{ comment: '1 серия' },
{ comment: '2 серия' },
],
},
{
comment: '2 сезон',
folder: [
{ comment: '1 серия' },
{ comment: '2 серия' },
{ comment: '3 серия' },
],
},
];
const ItemsList = ({ header, items, active, onChange }) => (
<div>
<h3>{header}</h3>
<ul className="items">
{items.map(({ comment }, i) => (
<li
className={`item ${active === i ? 'active' : ''}`}
onClick={() => onChange?.(i !== active ? i : -1)}
>
{comment}
</li>
))}
</ul>
</div>
);
function App() {
const [ iSeason, setActiveSeason ] = useState(-1);
const [ iEpisode, setActiveEpisode ] = useState(-1);
const season = SERIES[iSeason];
const episode = season?.folder[iEpisode];
useEffect(() => {
setActiveEpisode(-1);
}, [ iSeason ]);
return (
<div>
<ItemsList
header="сезоны"
items={SERIES}
active={iSeason}
onChange={setActiveSeason}
/>
{season && <ItemsList
header="серии"
active={iEpisode}
onChange={setActiveEpisode}
items={season.folder}
/>}
{episode && <div>Выбрали: {season.comment}, {episode.comment}</div>}
</div>
);
}
The functions passed to thereducers
parameter can be accessed through thecaseReducers
return field.
playlistSlice.caseReducers.playAudio(state, { payload: state.id });
<div class="div1">
<div class="div2">
Тут контент
</div>
</div>
.div1 {
width: 300px;
height: 500px;
overflow: hidden;
}
.div2 {
overflow-y: scroll;
max-height: 100%;
width: 100%;
padding-right: 45px;
background: lightpink;
}
Object.values(arr1.reduce((acc, { user_id: id, ...n }) => {
Object.entries(n).forEach(([ k, v ]) => acc[id][k] = (acc[id][k] || 0) + v);
return acc;
}, Object.fromEntries(arr2.map(n => [ n.id, {...n} ]))))
Map
:[...arr1.reduce((acc, { user_id: id, ...n }) => {
const obj = acc.get(id);
Object.entries(n).forEach(([ k, v ]) => obj[k] = (obj[k] || 0) + v);
return acc;
}, new Map(arr2.map(n => [ n.id, {...n} ]))).values()]
Object.values
извлекаем данные из объекта через map
по исходному массиву:arr2.map(function(n) {
return this[n.id];
}, arr1.reduce((acc, { user_id: id, ...n }) => (
Object.keys(n).forEach(k => acc[id][k] = (acc[id][k] || 0) + n[k]),
acc
), Object.fromEntries(arr2.map(n => [ n.id, {...n} ]))))
.querySelector
вместо этого создайте хук useState
храните в нем ваше значение и используйте переменную где хотите. При необходимых ситуациях можно и изменять это значениеconst [ text, setText ] = React.useState('Text1');
<h3 className='text'>{text}</h3>
setText('новый текст');