Q
运行
1
A
回答
1
我解决它......
看到这个fiddle更新的样本。
我最初的ListView
定义的didInsertElement
方法绑定到窗口的resize事件并更新ListItem
的宽度和高度,但这样一来我显然推翻了ListItem
自己didInsertElement
方法:
App.ListView = Ember.ListView.extend({
height: 500,
width: 500,
elementWidth: 80,
rowHeight: 20,
itemViewClass: Ember.ListItemView.extend({
templateName: 'row_item'
}),
adjustLayout: function(w, h) {
console.log(w, h);
this.set('width', w);
this.set('height', h);
},
didInsertElement: function() {
view = this;
$(window).resize(function() {
width = $('body').width();
height = $('body').height();
view.adjustLayout(width, height);
});
}
通过使用.on('didInsertElement')
代码工作:
App.ListView = Ember.ListView.extend({
height: 500,
width: 500,
elementWidth: 80,
rowHeight: 20,
itemViewClass: Ember.ListItemView.extend({
templateName: 'row_item'
}),
adjustLayout: function(w, h) {
console.log(w, h);
this.set('width', w);
this.set('height', h);
},
observeResize: function() {
view = this;
$(window).resize(function() {
width = $('body').width();
height = $('body').height();
view.adjustLayout(width, height);
});
}.on('didInsertElement')
+0
你应该换行代码处理resize事件中'Ember.run',以避免自动运行。 –
+0
感谢卢克,我将它转换成一个混合https://gist.github.com/bazzel/8962240/raw/4cf738cdce5ecbe04c217a2a81aaed5bd1bcc7c7/ember-list-view.js.coffee – bazzel
相关问题
- 1. 从rvm运行gem运行
- 2. 从命令行运行“即时运行”
- 3. 从IDE运行GUI函数时运行,但运行jar时不运行
- 4. SocketError:getaddrinfo在运行时运行heroku运行rake db:在Heroku上运行Rails4种子
- 5. 并行运行
- 6. 平行运行
- 7. 并行运行
- 8. Netsh.exe运行行
- 9. 从扩展运行方法扩展运行扩展运行
- 10. 如何在Ubuntu中运行PyCharm - “运行在终端”或“运行”?
- 11. 程序在Eclipse中运行,但运行jar不运行
- 12. 运行
- 13. 运行
- 14. 运行
- 15. 运行
- 16. 运行
- 17. 运行
- 18. 运行
- 19. 运行
- 20. 运行
- 21. 运行
- 22. 运行
- 23. 运行
- 24. 运行
- 25. 运行
- 26. 运行
- 27. 运行
- 28. 运行
- 29. 运行
- 30. 运行
你能提供一个jsFiddle吗? – chopper
对不起。现在包含示例。 – bazzel