如何管道到另一个require模块中的对象

时间:2015-01-05 19:19:26

标签: famo.us

我在模块中有一个scrollview,它加载从其他模块返回的视图。

包含scrollview的模块:

define(function(require, exports, module) {
    var View = require('famous/core/View');
    var Utility = require('famous/utilities/Utility');
    var Scrollview = require('famous/views/Scrollview');
    var HomeView = require('views/HomeView');
    var DescriptionView = require('views/DescriptionView');

    var paginationView = new Scrollview({
        direction: Utility.Direction.X
    });

    var AppViews = [
        HomeView,
        DescriptionView
    ];

    paginationView.sequenceFrom(AppViews);

    module.exports = paginationView;
});

以下是模块代码

define(function(require, exports, module) {
    var View = require('famous/core/View');
    var Surface = require('famous/core/Surface');
    var FlexScrollView = require('famous-flex/FlexScrollView');
    var MainView = require('views/MainView');
    var EventHandler = require('famous/core/EventHandler');

    function HomeView() {
        View.apply(this, arguments);
    }

    HomeView.prototype = Object.create(View.prototype);
    HomeView.prototype.constructor = HomeView;

    HomeView.DEFAULT_OPTIONS = {};

    var homeView = new HomeView();
    var scrollView = new FlexScrollView();

    homeView.add(scrollView);

    for (var i = 0, temp; i < 40; i++) {
        var surface = new Surface({
            content: "Surface: " + (i + 1),
            size: [undefined, 200],
            properties: {
                backgroundColor: "hsl(" + (i * 360 / 40) + ", 100%, 50%)",
                lineHeight: "200px",
                textAlign: "center"
            }
        });

        surface.pipe(scrollView);
        // ... I want to pipe to the parent scrollview here ...

如何在第一个模块中将表面从第二个模块传送到滚动视图?我还在学习整个事件管道,我不知道如何在这里实现它。我知道,因为我继承了着名的View模块,所以我应该可以访问一些高级事件管理,但是在我的情况下我是如何做到的。

1 个答案:

答案 0 :(得分:5)

模块HomeView扩展了Famo.us View,因此您可以将曲面传递给HomeView

中的事件处理程序
// ... I want to pipe to the parent scrollview here ...
Surface.pipe(this._eventOutput);