5ucms论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 6523|回复: 1

[2.x] 7、POPASP快速入门第七课 模板文件的循环语句

[复制链接]

670

主题

785

帖子

8228

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8228
发表于 2019-4-1 15:30:06 | 显示全部楼层 |阅读模式
index.asp
  1. <!--#include file="../popasp_2.0/popasp.asp"-->
  2. <%

  3. '项目部署时不要手工去创建home文件夹,系统会自动创建该文件夹
  4. const APP_PATH = "./home"

  5. '项目部署的时候使用POP_MVC.start方法,项目部署完之后使用POP_MVC.run方法
  6. POP_MVC.run
  7. %>
  8. <%
  9. Call A_("Index/index")
  10. dim key,item
  11. %>
  12. <html>
  13. <head>
  14. <title>变量类型转化</title>
  15. </head>
  16. <body>
  17.         <ul>
  18.                 <% for each key in V_("list") : set item = V_("list")(key) %>
  19.                         <li><a href="post.asp?id=<%=item("id")%>"><%=item("title")%></a></li>
  20.                 <% next %>
  21.         </ul>
  22. </body>
复制代码


arr.asp
  1. <!--#include file="../popasp_2.0/popasp.asp"-->
  2. <%

  3. '项目部署时不要手工去创建home文件夹,系统会自动创建该文件夹
  4. const APP_PATH = "./home"

  5. '项目部署的时候使用POP_MVC.start方法,项目部署完之后使用POP_MVC.run方法
  6. POP_MVC.run
  7. %>
  8. <%
  9. Call A_("Index/arr")
  10. dim key,item
  11. %>
  12. <html>
  13. <head>
  14. <title>变量类型转化</title>
  15. </head>
  16. <body>
  17.         <ul>
  18.                 <% for each item in V_("a") %>
  19.                         <li><%=item%></li>
  20.                 <% next %>

  21. <hr>               
  22.        
  23.                 <% for each key in V_("b") : item = V_("b")(key) %>
  24.                         <li><span><%=key%></span>:<span><%=item%></span></li>
  25.                 <% next %>
  26.         </ul>
  27. </body>
  28. </html>
复制代码


IndexAction.class.asp
  1. <%
  2. ' 本类由系统自动生成,仅供测试用途
  3. Class IndexAction
  4.     public Sub index()
  5.                 dim rs
  6.                
  7.                 '在这里获取到的rs为Recordset对象
  8.                 set rs = M_("post").db.page( "null,10" ).field("id,title").select()
  9.                
  10.                 '能过that.assign分配Recordset对象类型的变量时,会转化为Dictionary类型
  11.                 that.assign "list",rs
  12.                
  13.                 var_export typename( V_("list") )
  14.     end Sub
  15.        
  16.         public sub post
  17.                 dim rs
  18.                
  19.                 '在这里获取到的rs为Recordset对象
  20.                 set rs = M_("post").db.fieldRev("content").find()
  21.                
  22.                 that.assign "row",rs
  23.                
  24.                 var_export M_("post")
  25.         end sub
  26.        
  27.         public sub arr
  28.                 dim a,b
  29.                
  30.                 a = POP_MVC.Arr.Range(5,15) '定义5-15的一维数组
  31.                
  32.                 that.assign "a",a
  33.                 var_export typename( V_("a") )
  34.                
  35.                 '将数组转化成Dictionary对象之后,键值为0,1,2...,也就是原数组的下标
  36.                 that.assign "b",POP_MVC.Arr.toDict( a )
  37.                
  38.                
  39.         end sub
  40. End Class
  41. %>
复制代码

回复

使用道具 举报

670

主题

785

帖子

8228

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8228
 楼主| 发表于 2019-4-1 15:47:55 | 显示全部楼层
POP_MVC.Arr.toDict(xxx)  把xxx从数组对象 转换为 Dictionary类型数据
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|5ucms.com

GMT+8, 2024-3-29 13:03 , Processed in 0.593750 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表