admin管理员组文章数量:1415145
Here is a scenario:
I load data when controller is init. And when loading is finished. I want to resize the container element's size according the load data. So here is the problem, how can i access the view in a controller?
I know i can manipulate dom in view by this.$()
but how can i access dom in controller or how can i access view in controller. I use Ember.Router
here. So i dont create view and controller manually.
,html I show some code sample here. The code can not be executed, but it can show my problem. I did some ments on the code where have the problem.
Here is a scenario:
I load data when controller is init. And when loading is finished. I want to resize the container element's size according the load data. So here is the problem, how can i access the view in a controller?
I know i can manipulate dom in view by this.$()
but how can i access dom in controller or how can i access view in controller. I use Ember.Router
here. So i dont create view and controller manually.
http://jsbin./oxudor/edit#javascript,html I show some code sample here. The code can not be executed, but it can show my problem. I did some ments on the code where have the problem.
Share Improve this question edited Jul 17, 2012 at 17:24 aisensiy asked Jul 17, 2012 at 5:52 aisensiyaisensiy 1,5183 gold badges27 silver badges46 bronze badges 02 Answers
Reset to default 7I think you should not play with dom in the controller. That breaks MVC. Perhaps one solution could be to define an observer in the view, listening to the content of the controller. In this observer, then play with the dom (you're in the view, so no problem). As @pangratz suggests, with some code, perhaps I can give you a more plete answer.
EDIT: I think you could put the carousel function in the related view, and observes the controller.loading property. Here you could retrieve the jquery object of the view by using this.$().
carousel: function() {
var context = this.get('controller'),
self = this;
if(context.get('loading') === false) {
setTimeout(function() {
var width = self.$('#page_wrapper').width(),
num = self.$('.page').size();
self.$('#pages').width(width * num);
self.$('.page').width(width);
console.log([width, num]);
console.log(context.get('elements'));
}, 100);
}
}.observes('controller.loading')
Hope this help...
Now you can use Modifiers, Install Ember-midifier library and see this tutorial Ember-Modifiers
本文标签: javascriptHow can i manipulate dom in controller in emberjsStack Overflow
版权声明:本文标题:javascript - How can i manipulate dom in controller in emberjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745227524a2648678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论