0
我需要显示1000行的表格。但是,当我通过内容控制,页面不几秒ember.js对于大数据非常缓慢
下面内做出回应是我写的,显示问题的代码
你可以看到在http://emberjs.jsbin.com/qixoruyi/8/edit
工作演示,当我点击“更改内容“按钮,页面在几秒钟内没有响应,此时,计数器不增加,此时此时ember不会将控制权返回给javascript事件循环。 1000行对于余烬来说太多了?或者我做错了什么?
<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);
}
},
});
谢谢您的回答!
张贴了顺便说一句,是不是有点棘手,为用户应对?将无限滚动使用像烬斗篷[1](http://eviltrout.com/2014/01/04/hiding-offscreen-ember.html)[2](https://github.com/eviltrout/ember外壳)是一个更好的选择? – bcmcfc
为了在Ember中渲染大型表格,我通常最终使用[ember-table](https://github.com/Addepar/ember-table)。它以非常好的方式处理性能问题和延迟加载等内容。 –
“显示事物列表”的Emberjs故事目前非常低劣。老实说,我不确定他们如何认真对待这个问题,而不去处理。请注意,1000行不是任何延伸的“大数据”。事实上,Emberjs严重的性能问题可能会在100行内遇到。 “Ember Cloaking”项目可能会对你有所帮助,显然他们正在重构可怕的非高性能模板渲染系统,并且即将重写,但几个月来没有任何更新。 – Purrell