我有一个数组,我需要除以(5)并以5秒的间隔在5行(div)中显示它的元素。 例如:如果数组大小为15,则应首先显示0..4和第二次迭代,它应显示5 ... 9,并在给定的5个div上显示最后一次迭代10..15。
我创造了一个工作正常的小提琴。
我的问题是,我在页面加载后动态填充此数组,而不是在应用程序启动时。因此,它不会如上所述循环数组。 (为了操纵这个,我已经把settimeout放到了上面的小提琴上。)它不能用于settimeout,如果我把它评论出来,那么它就可以了,因为数组已经在页面开始加载了。
请帮助解决此问题..
//setTimeout(function(){
$scope.resutls = [{number:'1',name:'SHE SO CUTE'},
{number:'2',name:'SHE SO CUTE1'},
{number:'3',name:'SHE SO CUTE2'},
{number:'4',name:'SHE SO CUTE3'},
{number:'5',name:'SHE SO CUTE4'},
{number:'6',name:'SHE SO CUTE5'},
{number:'7',name:'SHE SO CUTE6'},
{number:'8',name:'SHE SO CUTE7'},
{number:'9',name:'SHE SO CUTE8'},
{number:'10',name:'SHE SO CUTE9'},
{number:'11',name:'SHE SO CUTE10'},
{number:'12',name:'SHE SO CUTE11'},
{number:'13',name:'SHE SO CUTE12'},
{number:'14',name:'SHE SO CUTE13'},
{number:'15',name:'SHE SO CUTE14'},
{number:'16',name:'SHE SO CUTE15'}];
//}, 3000);
答案 0 :(得分:1)
您可以将启动间隔的代码放在函数中,并在数据到达时调用该函数:
setTimeout(function(){
$scope.resutls = [{number:'1',name:'SHE SO CUTE'},
{number:'2',name:'SHE SO CUTE1'},
{number:'3',name:'SHE SO CUTE2'},
{number:'4',name:'SHE SO CUTE3'},
{number:'5',name:'SHE SO CUTE4'},
{number:'6',name:'SHE SO CUTE5'},
{number:'7',name:'SHE SO CUTE6'},
{number:'8',name:'SHE SO CUTE7'},
{number:'9',name:'SHE SO CUTE8'},
{number:'10',name:'SHE SO CUTE9'},
{number:'11',name:'SHE SO CUTE10'},
{number:'12',name:'SHE SO CUTE11'},
{number:'13',name:'SHE SO CUTE12'},
{number:'14',name:'SHE SO CUTE13'},
{number:'15',name:'SHE SO CUTE14'},
{number:'16',name:'SHE SO CUTE15'}];
start();
//alert("Hello");
}, 3000);
请参阅此fiddle。