GithubHelp home page GithubHelp logo

Comments (4)

otakustay avatar otakustay commented on July 16, 2024

参考 #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属性,保留原值(现在是会覆盖的,我会去修改)。

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

from er.

killeryyl avatar killeryyl commented on July 16, 2024

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

from er.

otakustay avatar otakustay commented on July 16, 2024

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

from er.

otakustay avatar otakustay commented on July 16, 2024

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

from er.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.