Javascript 如何通过for循环将项目拆分为3列?
如何通过for循环将项目(网格)拆分为容器的3列 我的输出不符合我的要求Javascript 如何通过for循环将项目拆分为3列?,javascript,angularjs,typescript,for-loop,Javascript,Angularjs,Typescript,For Loop,如何通过for循环将项目(网格)拆分为容器的3列 我的输出不符合我的要求 let array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', and more++]; Let say array will display multiple grid. let rowcount = Math.Ceil(array.length / 3) for (let i < 1; i < array.length; i+
let array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', and more++];
Let say array will display multiple grid.
let rowcount = Math.Ceil(array.length / 3)
for (let i < 1; i < array.length; i++){
return i++;
}
Mine output:- have 7 length of array , after rowcount will get
a b c
d e f g
Wrong...
Expected Output:-
a b c
d e f
g more more
more more more
more more more
more more more
more more more
more more more
more more more
more
let array=['a','b','c','d','e','f','g',等等+++];
假设数组将显示多个网格。
让rowcount=Math.Ceil(array.length/3)
for(设i<1;i
我想在每一行中打印3项,在下一行中打印3项,即使没有3项(可能只有1或2项)。
有人知道解决方案吗?这应该可以解决问题:
让rowCount=3;
//例如,构建临时数组
设arr=[…数组(100)].map((e,i)=>i);
for(设i=0;i }
您可以使用ng repeat
和查看$index
的值来实现这一点。下面是一个示例,使用一些CSS应用float
和clear
来模拟列。ng repeat
需要唯一的值,因此我使用了track by
,以防您的集合没有唯一标识符
angular.module('app',[])
.controller('ctrl',函数($scope){
$scope.items=[];
for(设i=65;i<91;i++){
$scope.items.push(String.fromCharCode(i));
}
});
.column{
宽度:50px;
浮动:左;
文本对齐:居中;
}
.最后{
清除:左;
}
{{item}}
您只想打印3个项目,然后转到下一行?欢迎使用StackOverflow!不幸的是,您的问题有点模糊。您要拆分的数组是什么?预期的输出是什么?三个数组?一个Html表?您的意思让人非常困惑。您的数组看起来像什么?是多维数组还是应该是b分块…?请提供您拥有的数据以及数据的外观。当您说“列”时,我很感激您对请求进行格式化,使其在视觉上有意义,但我们不知道您指的是页面上的列还是数据中的列?致:Michael Platt YesTo:zfrisch AddedThanks all,我发现使用mod语法会有所帮助,即总计%3.