Массив передан как проп, принят как строка

Это мое окончательное решение, основанное на ответе Тони:

template <typename T>
std::string stringForNumber( T f, int precision /* = 0 */, bool fixedWidth /*= false*/ )
{
    std::ostringstream ss;
    ss.setf(std::ios_base::fixed);
    if (precision > 0)
        ss << std::setprecision(precision);

    ss << f;
    std::string str(ss.str());
    if (!fixedWidth) // Removing trailing 0
    {
        const auto pointLocation = str.find_first_of(".,");
        if (pointLocation != std::string::npos)
        {
            const auto lastZeroPos = str.find_last_of('0');
            const auto lastNotZeroPos = str.find_last_not_of('0');
            if (lastNotZeroPos == pointLocation) // Integer number
                str.erase(pointLocation);
            else if (lastZeroPos != std::string::npos && lastNotZeroPos != std::string::npos && pointLocation < lastZeroPos && lastNotZeroPos < lastZeroPos)
            {
                str.erase(lastNotZeroPos+1);
            }
        }
    }

    return str;
}
0
задан Jon Dujaka 17 January 2019 в 09:45
поделиться

2 ответа

проблема:

<Table usersList="{test}" />

исправить:

<Table usersList={test} />
0
ответ дан Danyal Imran 17 January 2019 в 09:45
поделиться

Проблема в том, как вы передаете опору, которая имеет форму струны. Вместо этого вам нужно написать

<Table usersList={test} />

Как только вы сделаете вышеуказанные изменения, вы можете просто получить доступ к элементам массива, сопоставив реквизиты, как

this.props.usersList.map(...)
0
ответ дан Shubham Khatri 17 January 2019 в 09:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: