javascript - 在route.render()调用中自定义Ember View(或替代方法)

标签 javascript twitter-bootstrap view ember.js single-page-application

我正在尝试创建一个通用模式对话框 View ,我可以从应用程序中的任何 Controller 调用它。我已经有类似的工作:

App.ModalManaging = Ember.Mixin.create({
actions: {
    openModal: function (modalName, model, callback) {
        this.controllerFor(modalName)
            .set("model", model);
        this.set("modal", {
            callback: callback,
            name: modalName
        });
        this.render(modalName, {
            into: "application",
            outlet: "modal",
            controller: "application",
            view: "modal"
        });
    }
    //... other stuff
});

因此,对于每个模式,我创建一个单独的 Controller 类并将提供的对象设置为其模型。然后我使用 render() 方法将模态视图/ Controller /模板渲染到主布局中的“模式”套接字中。模态收集用户操作并向调用 Controller 提供响应的方式超出了本问题的范围。可以说,这部分是有效的。

嗯,这部分也有效,但我不喜欢它。每个模式的 Controller 似乎有点矫枉过正。我所需要的只是一个具有一些属性的 View ,它可以直接与应用程序路由通信。

所以在过去的几个小时里,我一直在尝试以某种方式自定义 render() 方法使用的 View 对象。

这不起作用:

this.render(modalName, {
    into: "application",
    outlet: "modal",
    controller: "application",
    view: new App.ModalView({
        message: "Are you sure?"
    })
});

我正在浏览 ember 源代码,似乎也没有这样的东西:

this.render(modalName, {
    into: "application",
    outlet: "modal",
    controller: "application",
    view: "modal",
    viewHash: {
        message: "Are you sure?"
    }
});

基本上,我需要 {{view}} 帮助程序的编程等效项,包括提供我自己的哈希的能力。

我想我可以使用固定的 ContainerView 而不是空 socket 并对其进行操作,但这看起来与模态 Controller 一样笨拙。

任何有关如何实现此目标或类似目标的想法将不胜感激。

最佳答案

更新:使用私有(private) router._lookupActiveView() 方法来实现此目的的方法。

var modalView = App.ModalView.create({
    templateName: modalName,
    message: "Are you sure?"
});
this.router._lookupActiveView("application")
    .connectOutlet("modal", modalView);

这似乎有效,但我不确定使用私有(private)方法是否比使用 Controller ->模型和 ContainerView 的笨重解决方案更好。

仍在寻找一种可靠的、规范的解决方案。

关于javascript - 在route.render()调用中自定义Ember View(或替代方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620109/

相关文章:

javascript - apollo graphql 传递参数来解析函数

javascript - 在 React 中使用 PropTypes 将字符串值作为对象传递给 Redux 组件

css - 将 Bootstrap Dropdown 置于最前面

Javascript 不等待使用 bootstrap-wizard.js 的 ajax

mysql - 在 mySQL 和 VIEW 创建中分配排名

view - SwiftUI:如何使用计时器在不同位置创建多个 View ?

javascript - 使用javascript隐藏和显示菜单ID

javascript - AngularJS - 在表单提交操作之前运行并等待异步函数

jquery - Laravel - 重定向回选项卡 Pane

mysql - 如何使用具有 View 的 phpmyadmin 导入 sql?