H
H
hollanditkzn2017-11-15 09:49:46
Web development
hollanditkzn, 2017-11-15 09:49:46

Why is the array not converted using array.map?

I use this code, but the data is not converted, I don’t understand why

Order.find()
        .then(orders => {
            orders = orders.map((order) => {
                if (order.status === 0){
                    order.status = 'Новый';
                }
                order.time = moment(order.time).format('DD MMMM YYYY');
                console.log(order);
                return order;
            });
            res.render('user', {
                username: req.user.username,
                title: 'Главная страница',
                order: orders
            });
        })
        .catch(err => console.log(err));

I receive such data, I will output it to only one object
{ _id: 5a0bdde700a4c7168416e8ef,
orderId: 16,
description: 'Test',
number: 10,
information: '',
file: 'Screenshot 2017-08-21 14.48.41.png',
name: 'Vasily',
phone: '79503164233 ',
email: '',
juid: null,
prepayment: null,
time: 2017-11-21T21:00:00.000Z,
prioity: 0,
__v: 0,
action: true,
createdAt: 2017-11-15T06:25: 18.636Z,
status: 0}

But I also receive in this format 2017-11-21T21:00:00.000Z
In the example, I set how the data should be displayed https://jsfiddle.net/rusline/gxzngwx6/6/ But there is an error and how to fix it?

Answer the question

In order to leave comments, you need to log in

9 answer(s)
S
Sanes, 2019-08-23
@Sanes


In addition, I don’t quite understand if you choose in favor of a framework, then it seems like they say JS is better than PHP (I don’t know why)
I don't see any advantage. Especially for projects where it is required to perform arithmetic operations.
Judging by the question, you yourself will not be able to implement this in any form.

A
Arseny, 2019-08-23
Matytsyn @ArsenyMatytsyn

Judging by the question, WordPress + WooComerce + Purchased \ Free theme and attempts to customize it or OpenCart + Alteration of the base theme.
A framework for a store is, with such a formulation of the question, a frankly crappy option, because: articles, nomenclature, income \ expenses, modifications, prices, charts, reports, customers, personal accounts, discounts, bonuses, promotions, currencies, VAT, delivery services, external APIs and another wagon and another wagon and a small cart of arguments against thoughtlessly dipping into something you don't understand. For self-development, it is possible and ... necessary, probably.

A
Adamos, 2019-08-23
@Adamos

Dummies are so tormented by this question, as if there is no simple answer for it.
If you need a typical solution (what has already been implemented hundreds of times on the Internet) - you need a CMS.
If you want to do something that no one has done or everyone does in their own way - a framework.
The store is, as a rule, obviously the first category.

B
Beetle, 2019-08-23
@Jukk

Framework is long, but will work the way you program it.
CMS is faster to deploy, customization will be a little through the ass (most likely you will have to change the system kernel code).
If you need special functionality (some special filter, a unique admin panel, something else unique), then of course the framework is better

N
Nikita Kolesnikov, 2019-08-23
@NikitOS_MV

It's up to you to decide
. If you have knowledge (or a desire to learn), you can try to write it yourself
Well, if you don't want to figure it out, then you can sms

D
Dmitry Brusensky, 2019-08-25
@BrusSENS

if there are questions about why php is better than js, then transfer the project to competent developers

A
Artem Kiryanov, 2019-08-25
@hacker342

An experienced developer will not create an online store from scratch on a framework if it is typical. A lot of people ask me about this too. There are already ready-made solutions. If you have a little knowledge of programming - OpenCart, wCommerce, etc., and in any case, you will need to finish it. If knowledge in the language is not enough, you take Bitrix with an online store license and you will get an almost ready-made store + uploads, etc. in 1C are already underway. As for the framework, well, here we need to understand what we want, as a rule, some systems are made on the framework, web applications for selling tickets, where there are ratings, etc.

H
hollanditkzn, 2017-11-15
@hollanditkzn

In mongus If you want simple objects, then you need
Order.find().lean().then ...

K
keslo, 2017-11-15
@keslo

What format do you have in the time field in the example? Apparently it should be a string?
https://jsfiddle.net/821cuanz/
In this case the code works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question