我需要显示包含 1000 行的表。但是当我将内容传递给控制器时,页面在几秒钟内没有响应
下面是我为显示问题而编写的代码
您可以在 http://emberjs.jsbin.com/qixoruyi/8/edit 查看工作演示
当我点击"更改内容"按钮时,页面在几秒钟内没有响应,此时计数器没有增加,那么此时余烬不会将控制权返回给javascript事件循环。1000 行对 Ember 来说太多了?还是我做错了什么?
<script type="text/x-handlebars">
<div>counter: {{counter}}</div>
<button {{action "changeContent"}}>change content</button>
<table border="1">
<tbody>
{{#each}}
<tr>
{{#each}}
<td>{{this}}</td>
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
</script>
var newContent = [];
var i,j, t, x=0;
for(i = 0; i < 1000; i++) {
t = [];
for(j=0; j<10; j++) {
t.push("x"+x++);
}
newContent.push(t);
}
App = Ember.Application.create();
App.Router.map(function() {});
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return [];
}
});
App.ApplicationController = Ember.ArrayController.extend({
counter: 0,
init: function() {
var t = this, c = 0;
setInterval(function(){
t.set('counter', c++)
}, 200);
},
actions: {
changeContent: function() {
this.set('content', newContent);
}
},
});
感谢您的回答!
我知道你的意思,我已经遇到了这个问题,所以试着检查我在stackoverflow中发布的解决方案