- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个 Controller :
$.Controller('App.Browse',
/** @Static */
{
defaults : {}
},
/** @Prototype */
{
init : function(){
$('#map').app_map();
},
// how can I listen here for an event of app_map() controller
})
和
$.Controller('App.Map',
/** @Static */
{
defaults : {}
},
/** @Prototype */
{
init : function(){
// how can I trigger an event to be listened by app_browser() controller
},
})
简短的想法是,当我在 App.Map
Controller 中时,我想注意到 App.Browse
Controller 正在做一些事情。
最佳答案
您可以尝试以下方法:
window.createEventManager = (function() {
var Event = function(manager, name) {
this.name = name;
this._manager = manager;
this._listeners = [];
};
Event.prototype = {
listen: function(fn) {
if (!$.isFunction(fn)) {
throw "fn is not a function.";
}
this._listeners.push(fn);
},
fire: function(args) {
args = args || {};
args.name = this.name;
var ls = this._listeners;
for (var i = 0, l = ls.length; i < l; ++i) {
ls[i](args);
}
this._manager.fire(args);
}
};
var EventManager = function(eventNames) {
for (var n in eventNames) {
this[eventNames[n]] = new Event(this, eventNames[n]);
}
this._listeners = [];
};
EventManager.prototype = {
/**
* Listen to all events
* @param fn
*/
listen: function(fn) {
if (!$.isFunction(fn)) {
throw "fn is not a function.";
}
this._listeners.push(fn);
},
fire: function(args) {
var ls = this._listeners;
for (var i = 0, l = ls.length; i < l; ++i) {
ls[i](args);
}
},
getEvent: function(name){
return this[name];
}
};
return function(eventNames) {
return new EventManager(eventNames);
};
})();
在 map Controller 中:
init : function(){
events = createEventManager(["mapTrigger"]);
},
然后在浏览器中通过以下方式收听:
$('#map').app_map().events.getEvent("mapTrigger").listen(function(){
// Logic to perform on trigger.
});
关于JavascriptMVC:在包装 Controller 中监听实例化 Controller 的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12835013/
这是我的第一篇文章 @ Stack Overflow :)我是一个长期的用户,总是在这里找到我的答案,但我在这里看不到太多关于 javascriptMVC 的信息...... 最近我开始研究它,遗憾的
我想开始我的 JavaScriptMVC 之旅,但我真的不知道如何正确安装它。我的意思是我知道,我可以将它放在 public_html 中,但是否可以将它放在系统中(例如 Rails?)。 Downl
我有以下网址: /tasks/ // Return a list of JSON /task/next-week/ // Return a list of JSON 我在
我有兴趣学习JavaScriptMVC .我已经阅读了入门指南和一堆官方文档,但我通过查看其他人的代码学习得最好。我在使用它的教程或示例/开源应用程序方面没有找到太多其他内容。 任何人都知道好的教程或
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
为什么在使用 javascriptmvc 开发 html5 应用程序时在 ie6 中出现错误? 当我在标题中包含时出现问题: 然后在关闭正文之前: 当我删除 html5shiv 时,该应用
我正在尝试使用 javascriptmvc 做简单的应用程序。 有几个 Controller 和下一个文件夹结构: /controllerA /views view1.ejs /i
在 JavascriptMVC 的 Controller 中,它们使用以下格式进行事件处理 代替经典的jquery $(function(){ $('#tabs').click(someCallb
我完全是 JavascriptMVC 的菜鸟,所以我正在学习教程。但我不得不说一些我确信非常简单的事情让我很困惑。在他们的一些教程中,他们引用了函数 assertEqual()。每当我尝试在开发环境中
有没有人尝试过集成jqGrid和JavaScriptMVC,特别是使用JMVC的模型封装来检索数据而不是jqGrid? 将 jqGrid 作为插件添加似乎很容易,但尝试将其合并到 MVC 模型中并不容
说我傻,但我很困惑。它们是否相同并且 can.js 只是它的继承者?它们似乎共享相当多的功能。由于 JavaScriptMVC 不像 CanJs 那样定期更新,我考虑切换到后者。有没有人有这方面的经验
我在这里搜索过,只找到一个类似的主题,但没有答案。我参与过多个 JavaScript MVC 项目,并且了解它的工作原理。我对 Ruby on Rails 不太精通,但我正在学习。现在我知道我有一些从
我一直在阅读有关 JavaScriptMVC 的文档框架,看起来很有趣。我想知道这里是否有人使用过该框架,并且取得了怎样的成功。 所以请与JavaScriptMVC分享您的经验, 如果你有任何。如果您
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试找出用于通过 AJAX 调用初始化的单例的正确模式。这是我已经完成的工作的简化示例。 它按预期工作,但我有一种感觉这不是“正确”的方式,并且有某种方法可以将初始化程序的回调挂接到当前正在运行
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我有 2 个 Controller : $.Controller('App.Browse', /** @Static */ { defaults : {} }, /** @Prototype
如何将 yui 与 javascriptmvc 集成? 我想在基于 javascriptMVC 的应用程序中使用 yui3.Tabview。 最佳答案 最好在 JMVC's forum 上提问。我在那
我正在使用 Modernizr 和 JavascriptMVC。 Modernizr 在头部。 在关闭 body 之前偷走: 当我像这样在 Controller 中添加一些 html5 内容时:
是否可以在 javascript 变量而不是脚本标签或文件中定义 View 模板? 像这样: var template = " "; var rendered = can.view.render(te
我是一名优秀的程序员,十分优秀!