Javascript 如何在angularjs中显示多行并限制行长度
我想使用angular js(带有一点CSS?)只在两条多行中输出一些行,每一行都应该有一个限制/长度,而且如果输出超过2行,最后一个字前面应该加“…”并仍然有两行 比如说,, aaaa、BBBB、cccc、dddd、eeee、ffff、gggg、hhhh、iiii 输出应为:Javascript 如何在angularjs中显示多行并限制行长度,javascript,html,css,angularjs,Javascript,Html,Css,Angularjs,我想使用angular js(带有一点CSS?)只在两条多行中输出一些行,每一行都应该有一个限制/长度,而且如果输出超过2行,最后一个字前面应该加“…”并仍然有两行 比如说,, aaaa、BBBB、cccc、dddd、eeee、ffff、gggg、hhhh、iiii 输出应为: aaaa, bbbbbbbb cccc, ... iiii 如有任何建议,我们将不胜感激 使用指令执行“值到多行”部分,以及 使用筛选器为过长的行插入省略号(“…”) 从技术上讲,对于(1)您不需要指令,只需要
aaaa, bbbbbbbb
cccc, ... iiii
如有任何建议,我们将不胜感激
…
这样的普通模板代码就可以了,但指令最终可能会更好
如果您尝试上述方法但仍然遇到问题,请使用JSFIDLE/plunkr编辑问题(或询问其他问题),以获得更具体的反馈
…
这样的普通模板代码就可以了,但指令最终可能会更好
如果您尝试上述方法但仍然遇到问题,请使用jsfiddle/plunkr编辑问题(或询问其他问题),以获得更具体的反馈。您只能使用css来完成此操作
<div id="test" class="verticalcut">aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii</div>
看看这个JSFIDLE:您只能通过使用css来实现
<div id="test" class="verticalcut">aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii</div>
看看这个JSFIDLE:它取决于从何处获得输入。如果您以字符串的形式获取输入,如下所示:
"aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii"
遵循以下步骤:
1) 在控制器中,创建范围变量并将其分配给输入数组。像这样:
angular.module('myApp',[])
.controller('myController', [function(){
//first convert input to an array. Be careful here. I'm assuming a space after each comma
this.input ="aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii".split(", ");
this.limit1 = 3//limit of characters in the first line. You could have any number here! Not just 3.
this.input2 = (this.input).slice(this.limit, this.input.length-2);//second line
this.final = this.input[this.input.length -1]; //final word
}]);
<body ng-controller="myController as ctrl">
<span ng-repeat = "word in ctrl.input|limitTo:ctrl.limit1">{{word}}, </span><br/>
<span ng-repeat = "word in ctrl.input2">{{word}}, </span>...{{this.final}}
</body>
2) 在您的视图中,您可以使用ng repeat来输出单词。像这样:
angular.module('myApp',[])
.controller('myController', [function(){
//first convert input to an array. Be careful here. I'm assuming a space after each comma
this.input ="aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii".split(", ");
this.limit1 = 3//limit of characters in the first line. You could have any number here! Not just 3.
this.input2 = (this.input).slice(this.limit, this.input.length-2);//second line
this.final = this.input[this.input.length -1]; //final word
}]);
<body ng-controller="myController as ctrl">
<span ng-repeat = "word in ctrl.input|limitTo:ctrl.limit1">{{word}}, </span><br/>
<span ng-repeat = "word in ctrl.input2">{{word}}, </span>...{{this.final}}
</body>
{{word}},
{{word},{{{this.final}}
这取决于您从何处获得输入。如果您以字符串的形式获取输入,如下所示: "aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii"
遵循以下步骤:
1) 在控制器中,创建范围变量并将其分配给输入数组。像这样:
angular.module('myApp',[])
.controller('myController', [function(){
//first convert input to an array. Be careful here. I'm assuming a space after each comma
this.input ="aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii".split(", ");
this.limit1 = 3//limit of characters in the first line. You could have any number here! Not just 3.
this.input2 = (this.input).slice(this.limit, this.input.length-2);//second line
this.final = this.input[this.input.length -1]; //final word
}]);
<body ng-controller="myController as ctrl">
<span ng-repeat = "word in ctrl.input|limitTo:ctrl.limit1">{{word}}, </span><br/>
<span ng-repeat = "word in ctrl.input2">{{word}}, </span>...{{this.final}}
</body>
2) 在您的视图中,您可以使用ng repeat来输出单词。像这样:
angular.module('myApp',[])
.controller('myController', [function(){
//first convert input to an array. Be careful here. I'm assuming a space after each comma
this.input ="aaaa, bbbbbbbb, cccc, dddd, eeee, ffff, gggg, hhhh, iiii".split(", ");
this.limit1 = 3//limit of characters in the first line. You could have any number here! Not just 3.
this.input2 = (this.input).slice(this.limit, this.input.length-2);//second line
this.final = this.input[this.input.length -1]; //final word
}]);
<body ng-controller="myController as ctrl">
<span ng-repeat = "word in ctrl.input|limitTo:ctrl.limit1">{{word}}, </span><br/>
<span ng-repeat = "word in ctrl.input2">{{word}}, </span>...{{this.final}}
</body>
{{word}},
{{word},{{{this.final}}
您可以通过以下方式实现这一点:
创建一个指令,该指令根据要显示的线和每条线的高度设置元素的高度。然后用overflow:hidden设置一个类,并在html中设置指令中的值
角度模块('scopePropertiesModule',[])
.directive('zsLinesHeight',['$timeout',
函数(){
返回{
限制:“AE”,
范围:{
行:“=”,
高度:'='
},
链接:函数(范围、元素){
const lineHeight=scope.line*scope.height;
element.prop('parentElement').style.height=`${lineHeight}px`;
}
}
}
]);代码>
。显示更多或更少{
溢出:隐藏;
断字:断字;
线高:15px;
}
禁欲主义的混乱衰老的哲学理性在自身与深度的矛盾中最终陷害衰老的自杀海洋。无止境的意图——顶峰山脉决定了优势。决断爱情意图信念法右海得利衍生出自己的意图矛盾。精神仇恨战胜混乱自由性仇恨终极奇妙救赎。爱、正义、意图、神圣、自由、胜利、正义、美德、信念、信念。自己希望重新估价好的价值发挥权将无穷无尽。战斗顶峰重新估价基督教权利获得价值美德法。厌恶的厌恶
爱、正义、意图、神圣、自由、胜利、正义、美德、信念、信念。自己希望重新估价好的价值发挥权将无穷无尽。战斗顶峰重新估价基督教权利获得价值美德法。厌恶的厌恶
您可以通过以下方式实现这一点:
创建一个指令,该指令根据要显示的线和每条线的高度设置元素的高度。然后用overflow:hidden设置一个类,并在html中设置指令中的值
角度模块('scopePropertiesModule',[])
.directive('zsLinesHeight',['$timeout',
函数(){
返回{
限制:“AE”,
范围:{
行:“=”,
高度:'='
},
链接:函数(范围、元素){
const lineHeight=scope.line*scope.height;
element.prop('parentElement').style.height=`${lineHeight}px`;
}
}
}
]);代码>
。显示更多或更少{
溢出:隐藏;
断字:断字;
线高:15px;
}
禁欲主义的混乱衰老的哲学理性在自身与深度的矛盾中最终陷害衰老的自杀海洋。无止境的意图——顶峰山脉决定了优势。决断爱情意图信念法右海得利衍生出自己的意图矛盾。精神仇恨战胜混乱自由性仇恨终极奇妙救赎。爱、正义、意图、神圣、自由、胜利、正义、美德、信念、信念。自己希望重新估价好的价值发挥权将无穷无尽。战斗顶峰重新估价基督教权利获得价值美德法。厌恶的厌恶
爱、正义、意图、神圣、自由、胜利、正义、美德、信念、信念。自己希望重新估价好的价值发挥权会被低估