博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ionic4-标题之显示开头和结尾,中间省略
阅读量:2493 次
发布时间:2019-05-11

本文共 1401 字,大约阅读时间需要 4 分钟。

目录

前情

        因为要将后端查询回来的标题名称显示到页面上,但是有得标题名称十分的长并且是系列课程的话,显示在页面中就会无法区分,所以特地将名称的开头与结尾显示出来,中间内容省略。

代码

const dataUrl = 'brainstorming-web/brainStorming/queryListByStatesClassId/'            + this.states + '/' + this.classId;        this.http.get(dataUrl).subscribe(            res => {                if (res.json().code === '0000') {                    if (res.json().data.length > 0) {                        // 查询回来的内容                        this.test = res.json().data;                        for (let i = 0; i < this.test.length; i++) {                            // 将每条数据中的名称进行截取                            let name = this.test[i].theme;                            let title = '';                            const nameLength = name.length;                            console.log('看一下name长度', nameLength);                            if (nameLength > 4) {                                let titleLength = nameLength - 4;                                while (titleLength > 0) {                                    title += '.';                                    titleLength--;                                }                                name = name.substr(0, 4) + title + name.substr(name.length - 2, name.length);                            }                            console.log('看一下效果-----', name);                        }                    }                }            }        );

显示结果

学习古诗……列一

转载地址:http://xcerb.baihongyu.com/

你可能感兴趣的文章
linux的基础知识
查看>>
接口技术原理
查看>>
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>
Git(四) - 分支管理
查看>>
PHP Curl发送数据
查看>>