admin管理员组文章数量:1025465
I am working with the API.
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description}
</Text>
);
};
I want to show only the first 50 characters of the description. How can I do that?
I am working with the API.
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description}
</Text>
);
};
I want to show only the first 50 characters of the description. How can I do that?
Share Improve this question edited Jul 13, 2020 at 17:36 monamona 1,2462 gold badges21 silver badges46 bronze badges asked Jul 13, 2020 at 15:44 NaiNai 551 silver badge9 bronze badges3 Answers
Reset to default 4Wele @Nai to StackOverflow,
You may use the pure JavaScript functions. slice
or maybe substring
.
Use of Slice:-
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description.slice(0, 50)}
</Text>
);
};
You can just use regular javascript functions to do that. In this case substring
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description.substring(0, 50)}
</Text>
);
};
Not exactly 50 characters, but you could achieve this with a bination of:
- Declare
numberOfLines
prop for text and set it to 1 / 2 (depending on your needs). - Declare
ellipsizeMode
with whatever you want it to be. - Set width of the container / text itself to the width you need and want to display.
Link to docs on Text in React Native.
This way you're making sure that your text is going to show correctly and no word is going to be cut in an ugly way.
I am working with the API.
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description}
</Text>
);
};
I want to show only the first 50 characters of the description. How can I do that?
I am working with the API.
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description}
</Text>
);
};
I want to show only the first 50 characters of the description. How can I do that?
Share Improve this question edited Jul 13, 2020 at 17:36 monamona 1,2462 gold badges21 silver badges46 bronze badges asked Jul 13, 2020 at 15:44 NaiNai 551 silver badge9 bronze badges3 Answers
Reset to default 4Wele @Nai to StackOverflow,
You may use the pure JavaScript functions. slice
or maybe substring
.
Use of Slice:-
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description.slice(0, 50)}
</Text>
);
};
You can just use regular javascript functions to do that. In this case substring
renderGridItem = (itemData) => {
return(
<Text>
{itemData.item.description.substring(0, 50)}
</Text>
);
};
Not exactly 50 characters, but you could achieve this with a bination of:
- Declare
numberOfLines
prop for text and set it to 1 / 2 (depending on your needs). - Declare
ellipsizeMode
with whatever you want it to be. - Set width of the container / text itself to the width you need and want to display.
Link to docs on Text in React Native.
This way you're making sure that your text is going to show correctly and no word is going to be cut in an ugly way.
本文标签: javascriptReact Native limit charactersStack Overflow
版权声明:本文标题:javascript - React Native limit characters - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745635091a2160397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论