简体   繁体   English

在这种情况下使用的最佳软件设计是什么

[英]What is the best software design to use in this scenario

I need to generate HTML snippets using jQuery. 我需要使用jQuery生成HTML代码段。 The creation of those snippets depends on some data. 这些摘要的创建取决于一些数据。 The data is stored server-side, in session (where PHP is used). 数据存储在服务器端的会话中(使用PHP)。

At the moment I achieved this 目前,我实现了这一目标
- retrieving the data from the server via AJAX in form of JSON -通过AJAX以JSON形式从服务器检索数据
- and building the snippets via specific javascript functions that read those data -并通过读取这些数据的特定javascript函数构建代码段

The problem is that the complexity of the data is getting bigger and hence the serialization into JSON is getting even more difficult since I can't do it automatically. 问题在于数据的复杂性越来越大,因此序列化到JSON变得更加困难,因为我无法自动执行。 I can't do it automatically because some information are sensible so I generate a "stripped" version to send to the client. 我无法自动执行此操作,因为某些信息很明智,因此我生成了一个“剥离”版本以发送给客户端。

I know it is difficult to understand without any code to read, but I am hoping this is a common scenario and would be glad for any tip, suggestion or even design-pattern you can give me. 我知道没有任何代码就很难理解,但是我希望这是一种常见的情况,对于您可以给我的任何提示,建议甚至设计模式,我都会感到高兴。

Should I store both a complete and a stripped data on the server and then use some library to automatically generate the JSON from the stripped data? 我是否应该在服务器上存储完整数据和剥离后的数据,然后使用一些库从剥离后的数据自动生成JSON? But this also means I have to get the two data synchronized. 但这也意味着我必须使两个数据同步。
Or maybe I could move the logic server-side, this way avoiding sending the data. 或者,也许我可以移动逻辑服务器端,以这种方式避免发送数据。 But this means sending javascript code (since I rely on jQuery). 但这意味着发送javascript代码(因为我依赖jQuery)。 Maybe not a good idea. 也许不是一个好主意。

Feel free to ask me more details if this is not clear. 如果不清楚,请随时询问我更多详细信息。

Thank you for any help 感谢您的任何帮助

There are several Javascript/jQuery templating solutions available. 有几种可用的Javascript / jQuery模板解决方案。 John Resig is working on one that's likely to become a popular jQuery add-on, if not part of the core distribution. John Resig正在研究一种可能会成为流行的jQuery附加组件(如果不是核心发行版的一部分)的组件。 Kyle Simpson is also doing one. 凯尔·辛普森(Kyle Simpson)也正在这样做。

I googled for a reference to it, but really I'd suggest doing your own searching because there's lots of good information out there. 我用谷歌搜索了它的引用,但实际上我建议您自己搜索,因为那里有很多很好的信息。

edit well here's a pretty good link: http://www.west-wind.com/Weblog/posts/509108.aspx 编辑良好,这里有一个很好的链接: http : //www.west-wind.com/Weblog/posts/509108.aspx

您可以使用PHP的json_encodejson_decode方法将本机PHP对象转换为JSON数据表示形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是最好的软件开发分析和设计工具,并能够将设计转换为实际代码? - What are the best Software Development Analysis and Design Tools and that have the ability to transform Design into Real Code? 在以下情况下,“开关”是否是最佳选择? - Is a “switch” the best to use in the following scenario? 客户在软件设计模式中意味着什么? - What does it mean by client in the software design patterns? 数据库获取或php生成之间的最佳性能方案是什么? - What will be the best performance scenario between database fetch or php generation 这个AJAX场景中最好的安全指南是什么,特别关注身份验证? - What are the best security guidelines in this AJAX scenario, with special regards to authentication? 最好的设计方法是更快的搜索? - What could be the best design approach faster search? 为软件开发人员创建PHP / MySQL升级脚本的最佳方法是什么? - What is the best way to create a PHP/MySQL upgrade script for a software developer? PHP / OOP设计问题,最佳实践是什么? - PHP/OOP design issue, what is best practice? 消耗REST API的最佳设计模式是什么 - What is the best design pattern to consume REST API 控制Flex + PHP软件版本的最佳方法是什么? - What is the best way to control Flex + PHP software version?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM