Events Famo.us-触发事件和管道
假设我有三种观点。AppView、MenuView和StripView。MenuView包含多个StripView,AppView包含一个MenuView。如何从StripView触发事件并在AppView上侦听该事件 编辑 假设我想在StripView上单击ImageSurface并在AppView上重新启动该事件,然后执行一些转换 我的解决方案 一切都基于Timbre应用程序,该应用程序是在著名的美国初学者工具包参考教程中创建的 //StripView.js(_setListeners()在StripView构造函数中调用,bodySurface在代码中定义) //MenuView.js(_createStripViews()在MenuView构造函数中调用)Events Famo.us-触发事件和管道,events,eventtrigger,famo.us,piping,Events,Eventtrigger,Famo.us,Piping,假设我有三种观点。AppView、MenuView和StripView。MenuView包含多个StripView,AppView包含一个MenuView。如何从StripView触发事件并在AppView上侦听该事件 编辑 假设我想在StripView上单击ImageSurface并在AppView上重新启动该事件,然后执行一些转换 我的解决方案 一切都基于Timbre应用程序,该应用程序是在著名的美国初学者工具包参考教程中创建的 //StripView.js(_setListeners()在
您希望使用视图内置处理程序来实现这一点。这些是_eventInput和_eventOutput。。下面是一个在StripView中使用ImageSurface并响应AppView中单击的示例 希望有帮助
// In StripView.js
var imageSurface = new ImageSurface();
imageSurface.on('click',function(){
this._eventOutput.trigger('image-click', { somedata:'some value'} );
}.bind(this));
// In AppView.js
var stripView = new StripView();
this.subscribe(stripView);
this._eventInput.on('image-click',function(data){
// Do Something
});
您希望使用视图内置处理程序来实现这一点。这些是_eventInput和_eventOutput。。下面是一个在StripView中使用ImageSurface并响应AppView中单击的示例 希望有帮助
// In StripView.js
var imageSurface = new ImageSurface();
imageSurface.on('click',function(){
this._eventOutput.trigger('image-click', { somedata:'some value'} );
}.bind(this));
// In AppView.js
var stripView = new StripView();
this.subscribe(stripView);
this._eventInput.on('image-click',function(data){
// Do Something
});
我可以使用emit代替触发器吗?我的stripView未在AppView中定义,多个stripView在MenuView中定义,一个MenuView在AppView中定义。我正在使用一些繁重的编程示例。我不确定我是否已经准备好进行那种级别的编程。我看你已经解决了。有很多方法可以将这些事件连接起来。没有一种方法总是正确的!:)我希望我已经弄明白了。对于未过期的程序员来说,Famo.us并不是那么容易,但结果非常棒。你的答案是对的。是的,事件是一个更复杂的话题,许多程序员都有过经验,也很熟悉。只是需要时间!你会成功的!我可以使用emit代替触发器吗?我的stripView未在AppView中定义,多个stripView在MenuView中定义,一个MenuView在AppView中定义。我正在使用一些繁重的编程示例。我不确定我是否已经准备好进行那种级别的编程。我看你已经解决了。有很多方法可以将这些事件连接起来。没有一种方法总是正确的!:)我希望我已经弄明白了。对于未过期的程序员来说,Famo.us并不是那么容易,但结果非常棒。你的答案是对的。是的,事件是一个更复杂的话题,许多程序员都有过经验,也很熟悉。只是需要时间!你会成功的!
function _setListeners() {
this.menuView.on('test',function(){
console.log("IT WORKS");
}.bind(this));
}
// In StripView.js
var imageSurface = new ImageSurface();
imageSurface.on('click',function(){
this._eventOutput.trigger('image-click', { somedata:'some value'} );
}.bind(this));
// In AppView.js
var stripView = new StripView();
this.subscribe(stripView);
this._eventInput.on('image-click',function(data){
// Do Something
});