如何设计通用 jquery ui 对话框视图 (backbonejs)
我有一个要求,我需要一个通用的 Backbone View,它将包含在 jquery UI 对话框中。该视图应提供以下功能:
- 可以从任何其他视图调用。
- 对话框视图输入字段值应传递回调用视图。
- 可以调用另一个视图(又是一个 jquery 对话框)并隐藏自身。当在新视图上单击“提交/确定”时,将再次显示先前的对话框。 (这里新对话框也会向调用对话框提供一些信息)
对于 1],我在每个必须调用对话框的视图中放置一个空 div。但这不是通用的。
对于2]当前我从对话框视图中设置了调用视图的某些字段。我对这个实现并不满意,因为: a] 我们正在从 diff 视图访问另一个视图元素,并且 b] 当多个视图调用对话框视图时,这会变得复杂。由于我需要一个标志来告诉我哪个视图称为此对话框视图,因此我可以设置其元素值。 在这种情况下,是否有更好的方法将信息从一个视图传递到另一个视图?
对于3]我还没有想出一个好的设计。
提前致谢。
I have a requirement where i need to have a generic Backbone View that will be enclosed in a jquery UI dialog. This view should provide the following functionalities:
- Can be called from any other View.
- The dialog views input fields value should to be passed back to the calling View.
- Can call another View ( again a jquery dialog ) and hide itself. When a Submit/OK is clicked on the new view the previous dialog will be shown again. ( here too the new dialog will give some information to the calling dialog)
For 1] I am putting an empty div in each view that has to call the dialog. But this is not generic.
For 2] Currently i set some field of the calling view from the dialog view. I am not happy with this implementation, since:
a] we are accessing another views elements from a diff view and
b] This becomes complex, when more than one view calls the dialog view. Since i need to have a flag to tell me which view called this dialog view, so i can set its elements value.
Is there a better way to pass information from one view to another in such a scenario?
For 3] I am yet to come up with a good design.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这就是你要找的,但这是我的技巧。它适用于我自己的项目之一,并且绝对可以改进。 “#addQuizDialog”是 DOM 中的一个空 div。我克隆它是因为我在其他代码的其他地方删除了它。动态添加 div 也是一种选择,但它给我带来了其他问题,我现在不记得了。
I don't think this is what you're looking for, but here's my hack. It works for one of my own projects and definitely could be improved. The "#addQuizDialog" is an empty div in the DOM. I clone it because I remove it elsewhere in other code. Adding the div dynamically is also an option, but it created other problems for me that I can't remember at this time.