Javascript MVC,需要结构/方法方面的帮助吗?
我正在尝试单页应用程序。我在某种程度上了解如何使用 mvc 的主要概念,并且正在使用一个名为backbone.js 的轻量级框架。然而,我的问题不在于骨气。实际上,我在弄清楚如何构建用户界面时遇到了问题。我在页面顶部有一个带有 4 个按钮的栏。每个按钮都会在应用程序中打开一个实例窗口。在每个实例窗口中都会使用 html、css、javascript。关于如何构建此用户界面的核心概念的任何建议。
我的考虑因素:
每个窗口实例都有它自己的 具有唯一ID的div(显示: 无)。
加载时,应用程序应该 已经有必要的html、css、 并将 JavaScript 加载到 dom 中。这 html 应该位于每个唯一的内部 与其实例相关的 div 加载
每个菜单按钮都应该修改它的div 显示:阻止,带来 该按钮的实例窗口 位于前面,但隐藏所有其他按钮。
每个实例窗口都必须是 足够灵活,可以运行 javascript 在其中,所以我必须能够 在每个中创建额外的mvc 唯一的 div。
好的,最后一条评论。我的用户应该 接口利用mvc或者是 这没有必要。另外,如果它确实使用了mvc 最好的完成方式是什么 这。有很多不同的概念 使用 MVC,就像创建视图一样 每个实例窗口和监听 点击次数。它只是变得令人困惑。
您认为我的任何考虑都会有效地完成工作,您能提供建议吗?
I am attempting a single page application. I understand the main concept of how mvc is used to some extent and am using a lightweight framework called backbone.js. My issue however is not with backbone. I actually am having a problem figuring out how to structure my user interface. I have a bar at the top of the page with 4 buttons. Each button opens an instance window within the application. Within Each of these instance windows html, css, javascript will be utilized. Any suggestions on how to structure the core concept of this user interface.
Considerations on my part:
Each window instance has it's own
div with a unique ID (display:
none).On-load, the application should
already have necessary html, css,
and javascript loaded into dom. The
html should be inside each unique
div pertaining to its instance
window.Each menu button should modify its divs
display: to block, bringing the
instance window for that button to
front, but hiding all others.Each instance window has to be
flexible enough to run javascript
within it, so I must be able to
create additional mvc's within each
unique div.Okay, last comment. Should my user
interface utilize mvc or is
it not neccessary. Also, If it did use mvc
whats the best way to acomplish
this. There many different concepts
with mvc, like creating a view for
each instance window and listening
for clicks. It just gets confusing.
You think any of my considerations will effectively get the job done, and can you offer suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管 Sencha 的 ExtJS 可能不适合您,但他们有一个非常详细的教程,介绍如何构建 MVC 框架。
我建议看看这个以获得一些想法: http://dev.sencha.com/deploy/ext-4.0-beta3/docs/guide/application_architecture.html
干杯!
Although Sencha's ExtJS may not be for you, they have a very detailed tutorial of how they've structured the framework for MVC.
I'd recommend taking a look at this for some ideas: http://dev.sencha.com/deploy/ext-4.0-beta3/docs/guide/application_architecture.html
Cheers!
如果我理解正确,您想让每个按钮显示一个弹出窗口,并能够根据某些操作更改每个弹出窗口的内容?我只能说出我将如何使用 ASP.NET MVC...
我将使用 jQuery UI Dialog处理弹出窗口,并在每个弹出窗口中都有一个
form
标记,该标记使用自己的 MVC 控制器,使用 ajax(我更喜欢 jQuery ajax 命令)。使用 ajax 而不是标准的提交按钮,您可以在不刷新网页的情况下向服务器发送数据或从服务器接收数据。您需要 .serialize 将表单转换为正确的发送格式。每个控制器操作可以返回一个 JsonResult (它返回一个可以使用的 javascript 对象)或一个 PartialView (它提供 HTML)...希望其中一些有意义...
编辑:
为了回答你的最后一点,我将为每个窗口都有一个模型、视图和控制器......但我对 MVC 模式相当陌生......
If I understand correctly, you want to have each button display a popup window, and be able to change the content of each popup window based on some action? I can only speak for how I would use ASP.NET MVC...
I would use jQuery UI Dialog to handle the popup windows, and have a
form
tag within each popup that uses its own MVC controller using ajax (I prefer the jQuery ajax command). Using ajax rather than a standard submit button allows you to send/receive data to/from the server without refreshing the webpage. You'll need the .serialize to convert your form into the correct format for sending. Each controller action can either return a JsonResult (which gives you back a javascript object you can use) or a PartialView (which gives HTML)...Hope some of that made sense...
EDIT:
To answer your last point, I would have a model, view and controller for each window... but I am fairly new to the MVC pattern...