Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View不能很好的自定义container #22

Closed
killeryyl opened this issue Mar 13, 2013 · 4 comments
Closed

View不能很好的自定义container #22

killeryyl opened this issue Mar 13, 2013 · 4 comments

Comments

@killeryyl
Copy link
Contributor

原ER框架里有loadSubByPath,这里是可以自定义view的container的,也就是用view实现了局部刷新。现在的ER里的container全部都指向了config里的mainElement,仅能在url里添加container参数达到刷新指定DOM的效果。虽然也可以自己添加路由解决这个问题,但总感觉这里被做死了,请指教。

@otakustay
Copy link
Member

参考 #5 ,因为暂时还没实现renderChildAction来指定,所以现在的ER看来没有你所说的功能。

在完整设想的ER中,完成你的功能有几个方法:

  • 使用controller.renderChildAction(url, container);进入一个Action,这个Action会把View渲染在指定的container

  • 自己写一个Action子类,重写render,在render()调用时,把自己的target根据model给的值改掉,代码:

    var View = require('er/View');
    function MyView() {}
    MyView.prototype.render = function() {
        this.container = this.model.get('targetContainer');
        View.prototype.render.apply(this, arguments);
    }
    require('er/util').inherits(MyView, View);
    
    // Action里
    createModel = function() {
        var model = Action.prototype.createModel.apply(this, arguments);    
        model.set('targetContainer', 'whatever');
        return model;
    }
    

你提的问题确实是没有考虑周全的(不包含非子Action也有这样的需求),因此会再额外加一个入口:

在Action的实现中,重写createView方法,得到View实例后,把其中的container赋值,此后Action就不会再覆盖container属性,保留原值(现在是会覆盖的,我会去修改)。

不知这样的解决方式是否能满足你的要求,如果有其它没顾及到的,请继续说明

@killeryyl
Copy link
Contributor Author

解决方法倒是蛮多的,但就像你说的Action.prototype.createModel.apply这样感觉总是怪怪的。不过现在还没到强制使用的地步,先等renderChildAction实现,大家或多或少都需要这个。我继续看其他功能。

@otakustay
Copy link
Member

80639d8 中加了一个功能,如果Action的createView返回的View实例有container字段,Action不会去覆盖他,允许用户在这里自定义容器。其它方面的办法可以继续讨论

@otakustay
Copy link
Member

没人讨论,这个方案已经执行,后续有其它需求再打开。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants