关于jqtouch的几个问题

发布于 2024-10-06 06:40:03 字数 1179 浏览 0 评论 0原文

我正在使用 Rails 3。请考虑底部列出的以下代码。

1) 应该通过 href (href="/foo/bar") 还是通过 #id (id="#foobar_div") 链接到其他操作?在我在线阅读的一些文档中。提供 href 属性的实际链接告诉 iPhone 执行 AJAX 调用。

如果我提供一个 div#id,那么它会在没有 ajax 的情况下加载页面(与浏览器执行此操作的方式相同)。但是,提供 div#id 意味着所有内容都必须声明为单个页面。

调用服务器上其他页面的正确方法是什么?

2)下面的代码结构有问题吗?即我可以像这样设计自己的跨度元素吗?

3) 演示页面表明所有内容都应该是在一页中。然而,railscast.com 的 Ryan Bates 有一个关于 jqtouch 的剧集,并且他的页面是单独的。哪个是正确的方法?

<ul>
  <% @songs.each do |song| %>
    <li class="arrow">
      <%= link_to(song_path(song)) do %>
        <%= image_tag(song.user.profile_image, :alt => 'profile image', :style => 'float:left;') %>
        <span class="title"><%= song.title %></span>
        <span class="artist">by <%= song.user.first_name %></span>
        <span class="likes"><%= song.likes.count %> loves</span>
      <% end %>
    </li>
  <% end %>
</ul>

I am using Rails 3. Consider the following code listed at bottom.

1) Should links to other actions be done via href (href="/foo/bar") or via #id (id="#foobar_div")? In some document I read online. Providing an actual link to the href attribute tells the iPhone to execute an AJAX call.

If I provide an div#id instead, then it loads the page without ajax (the same way browsers do this). However, providing div#id's means that all content has to be declared a single page.

Whats the right way for calling other pages on the server?

2) Is there anything wrong with the code structure below? i.e. can I style my own span elements like this?

3) The demo pages indicate that all content should be in one page. However, Ryan Bates from railscast.com has an episode about jqtouch and his pages are separate. which is the proper way?

<ul>
  <% @songs.each do |song| %>
    <li class="arrow">
      <%= link_to(song_path(song)) do %>
        <%= image_tag(song.user.profile_image, :alt => 'profile image', :style => 'float:left;') %>
        <span class="title"><%= song.title %></span>
        <span class="artist">by <%= song.user.first_name %></span>
        <span class="likes"><%= song.likes.count %> loves</span>
      <% end %>
    </li>
  <% end %>
</ul>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま昔日黯然 2024-10-13 06:40:03

对于你的第一个问题和第三个问题(对我来说这是问同一件事),这取决于你正在从事的项目。

如果你提供静态内容,你可以一次加载所有页面,因此使用“id=#foobar_div”,只要页面不是那么多(因为你不希望用户拿着手机在他们的朋友面前等待 30 分钟等待您的网站加载看起来很愚蠢)。

如果您提供动态内容或者您的网站页面太多,您可能需要使用 AJAX 方法,至少对于某些页面而言。

最重要的是,您希望加载尽可能多的静态页面,同时仍保持网站的响应能力。

对于问题2,我不太确定我是否明白你的要求。我看不出有什么明显的错误,但再说一遍,我不是铁路程序员。

For your first and third questions (which to me are the asking the same thing), it depends on the project you're working on.

If you're providing static contents, you can just load all the pages in one hit, hence using "id=#foobar_div", as long as there are not that many pages (as you don't want the users to hold the phone and look stupid in front of their friends waiting 30 minutes for your site to load).

If you're providing dynamic contents or there are too many pages for your site, you may want to use the AJAX approach, at least for some pages.

At the bottom line, you want to load as many static pages as possible while still keeping your site responsive.

For question 2, I'm not quite sure I got what you're asking. I can't see anything obviously wrong, but again, I'm not a rail programmer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文