锁定老帖子 主题:ROR的AJAX心得
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-07-12
ROR的AJAX心得 最近用ROR做了一个网站(http://www.bladearena.com),全部采用了AJAX来处理数据。在这个 首先还是要赞一下ROR,感觉使用起来入行云流水一般,一发不可收拾。在编码的时候经常一上去就觉得 说了那么多,还是来说说具体的一些心得体会吧。 2.关于数据传输的问题 3.div+css 4.AJAX分页 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-07-12
我认为需要重新审视RJS的作用。
如果ajax只是简单的做模板替换,用rjs还是客户端的纯javascript差别不大,都是那么一两行代码而已。 但如果控制复杂数据的更新,rjs代码里就既包含了数据,也包含了表现层的控制代码,后者依赖于调用页面上下文,隐约感到“脏”,是不是也有违REST原则? RJS让使用者不需写javascript代码的优势毫无疑问,但同时: 1. 严重绑定prototype.js家族。虽然rails的一站式让我们无须选择,但就javascript库来说,jquery等后来者更优秀,虽然有plugin支持它,但毕竟不是官方。 2. rjs vs javascript 代码的重用性。我们写的通用javascript,可以封装成单独的js文件被重用到非rails系统中,但rjs显然不行。 3. 学习成本。省了javascript的学习成本,又带来了rjs的学习成本,又是一个典型的成本转移。rjs对于复杂javascript的支持度(它有调用javascript function的表达,但要求使用者对rjs和javascript都要了解) 4. 开头提到的 数据与表现分离原则。我个人更喜欢服务器端返回json,而把控制UI的代码用纯javascript写(这时可以选用喜欢的jquery等)。这样,被外部系统集成的障碍就小很多。比如让google gadget的XMLHttpRequest访问,只需在gadget中引用json.js进行正反向解析。 |
|
返回顶楼 | |
发表时间:2007-07-13
搜了一下,这个blog开头几个回复跟我意见差不多:
http://blog.zerosum.org/?q=node/47 另发现有人在rjs和REST使用上出了问题: http://www.railsforum.com/viewtopic.php?pid=22592 我把前面几条引用过来了。 nap 写道 Like most people, I'd be happy to see the framework's impl of all things Javascript become a little less prototype-dependent. Making it pluggable to some extent so that alternative javascript libraries could be used (jquery, yahoo's YUI connection manager, etc) would be excellent. I guess that this may mean standardizing on a 'helper interface architecture' of some sort, some of which could be more RESTful in approach than others. Justin Jones 写道 At the end of the day, I think it's pretty clear that "merging" Ruby/Rails and JavaScript/Prototype is not exactly a great idea. It works awesome for simple remote form submits / remote links, but as you get more specific, it tends to break down. Just take a look at the source of the "major" rails apps (the only ones I've looked at) - anything from 37s and Blinksale. Most of the JS do is written in JS, not in Ruby. And this coming from someone (me) who isn't even particularly fluent in JS Dan Kubb 写道 nap: You're right that alot of the Javascript the helpers output doesn't really fit in with the RESTful way of things. Many of those were in place over a year before RESTful Rails caught on. RJS itself doesn't work too well with REST either. Justin's right on the money with his approach: In many cases it would be better to speak XML and have the JS parse it on the client side, rather than returning HTML/JS fragments. I'm hoping that Jester catches on and fill this gap. I've actually found something neat about the Rails patching process in that nearly every single patch that's even remotely related to REST has been accepted extremely quickly. I've even had a couple of patches committed to the core within a few hours of submitting them because they added or fixed something related to REST or the HTTP handling. I think if people can find a way of patching Rails' JS helpers to work better with REST that it'll be accepted quickly. Anything that isn't backwards compatible (like an AutoComplete that works with GET and XML) would fit nicely in a plugin for now. |
|
返回顶楼 | |
发表时间:2007-07-13
我也是习惯了自己写js,所以rjs就用用常见、简单的得了,大部分还是自己控制比较好
|
|
返回顶楼 | |
发表时间:2007-07-14
楼主做的吗? CSS布局好像不大好哦。 FF中看看新闻页面:)
|
|
返回顶楼 | |
浏览 5817 次