简体   繁体   English

渲染,局部视图。 我应该在模板中放什么?

[英]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.

相关问题 局部视图在索引视图中无法正常工作。 - Partial View not working propely in index view. javascript / jquery在部分视图中不起作用。 - javascript/jquery not working in the partial view. 我的第一个骨干模型/视图。 我在正确的轨道上吗? - My first backbone model / view. Am I on the right track? 在服务器上渲染部分视图或在客户端上发送json数据和渲染模板 - Render partial view on the server or send json data and render template on the client 我正在尝试使用第一个视图中路由器链接按钮中的 id 数据填充第二个视图。 不确定我是否应该通过 BaseURL - I'm trying to populate a second view with data by id from a router-link'd button in my first view. Not sure if I should go through the BaseURL 渲染局部视图。 Javascript文件不适用于该渲染视图吗? - Rendering a partial view. Javascript files dont apply to that rendered view? 骨干视图不呈现我的模板 - Backbone View doesnt render my Template IE 8-&gt; IE 7兼容性视图。 是什么触发的? - IE 8 -> IE 7 Compatibility view. What triggers it? 我应该使用JavaScript还是服务器渲染此模板? - Should I render this template using JavaScript or the server? 无法通过ViewBag在部分View的JQuery中发送参数。 - Can't send parameters by ViewBag in JQuery of partial View.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM