[英]Render, Partial, View. what should i put in my template?
I have an application where i wish to create a user profile widget. 我有一个应用程序,希望在其中创建用户个人资料小部件。 The widget will sit in the navbar in the application template. 该小部件将位于应用程序模板的导航栏中。 the widget will look like a login button that pops up a modal login dialog or a dropdown menu that contains links to various user related functions/routes. 小部件看起来像一个登录按钮,它会弹出一个模态登录对话框或一个下拉菜单,其中包含指向各种与用户相关的功能/路由的链接。
the logic for the widget is so far this: 到目前为止,小部件的逻辑是这样的:
{{#if 'user.loggedIn'}}
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"/> {{user.username}}</a>
<ul class="dropdown-menu">
<li>{{#link-to "profile" user}}Profile{{/link-to}}</li>
<li>{{#link-to "logoff" user}}Logout{{/link-to}}</li>
</ul>
{{else}}
<button class="btn btn-primary navbar-btn" data-target="#loginModal" data-toggle="modal">Login</button>
{{/if}}
I wish to have a controller handle the login functions and calling the modal prompt: 我希望有一个控制器来处理登录功能并调用模式提示符:
App.UserController = Em.ObjectController.extend({
loggedIn: Em.computed.readOnly('model.loggedIn'),
username: '',
password: '',
showLoginModal: function(){
Em.$("#loginModal").modal();
},
hideLoginModal: function() {
Em.$("#loginModal").modal('hide');
},
login: function() {
var username = this.get('username'),
success = true; //attempt a login
console.log('logging in as' + username);
if(success) {
this.send('hideLoginModal');
this.set('user.loggedIn', true);
}
return false;
}
});
So my question is, what is the best way to get this component/view/partial into the application template using the UserController for the widget? 所以我的问题是,使用窗口小部件的UserController将组件/视图/部分放入应用程序模板的最佳方法是什么?
I'm very new to ember so please be nice :). 我是炭烬的新手,所以请保持友善:)。
I would use a component for the view, and handle the login logic in the ApplicationController and the UserModel. 我将为视图使用一个组件,并处理ApplicationController和UserModel中的登录逻辑。
But actually, there are multiple ways to solve that problem! 但是实际上,有多种方法可以解决该问题! U could also do it directly in the applicationTemplate. 您也可以直接在applicationTemplate中执行此操作。
But: U should not use a normal view or partitial! 但是:U不应使用普通视图或偏见! Mostly u should use a component instead! 通常,您应该改用组件!
The render helper IS an option, if u need the View/Controller pattern, and if its not clearly seperated! 如果您需要View / Controller模式,并且没有明确分开,则可以使用渲染助手。
Generall: If u can seperate it, you should. 通用尔:如果你可以分开,那你应该。 And then u should use a component. 然后,您应该使用组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.