如何使用backbone.js跨多个视图实现通用功能
您好,我正在尝试使用backbone.js 跨多个视图实现自定义功能。例如,我需要应用程序中的所有输入文本框在接收焦点时更改其视觉外观。 我正在考虑从 Backbone.View.extend 继承 window.BaseView ,然后让我的所有视图扩展 BaseView 。 你能告诉我我的方向是否正确吗?您还有其他建议吗?你实施过类似的事情吗?
Hello I'm trying to implement a custom functionality across multiple views using backbone.js. For example I need to have all the input textboxes in the application to change their visual appearance when they receive focus.
I am thinking to inherit a window.BaseView from the Backbone.View.extend and then to have all my views to extend the BaseView.
Could you please tell me if I'm on the right direction? Do you have other suggestion? Have you implemented something similar ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会将通用功能放在基本原型中,并让所有视图扩展它,或者我会创建一个具有该功能的 mixin 对象并使用 mixin 扩展视图。
I would put the common functionality in a base prototype and have all the views extend it or I would create a mixin object that has the functionality and extend the view with the mixin.
我没有使用主干来完成类似的任务,因为不同的视图有不同的元素,并且多次绑定相同的焦点功能也是浪费的。我会做的是:
或CSS(不确定浏览器支持):
I didn't use backbone for similar task since different views have different elements and binding same focus function more than once is also wasteful. What I would do is either:
or CSS (not sure about browser support):