5ucms论坛

标题: 7、POPASP快速入门第七课 模板文件的循环语句 [打印本页]

作者: admin    时间: 2019-4-1 15:30
标题: 7、POPASP快速入门第七课 模板文件的循环语句
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. %>
复制代码


作者: admin    时间: 2019-4-1 15:47
POP_MVC.Arr.toDict(xxx)  把xxx从数组对象 转换为 Dictionary类型数据




欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2