第五十三章 开发自定义标签 – Using csr %cspQuote Methods

Using csr %cspQuote Methods

%cspQuote例程定义包含两个不同引用方法的定义。

  • Quote

  • QuoteCSP

Quote Method

$$Quote^%cspQuote(line As %String)

用引号将输入字符串括起来。

QuoteCSP Method

$$QuoteCSP^%cspQuote(line As %String)

用引号将输入字符串括起来,并解析#()###()###''##server#url调用。

创建<grid>标记以显示表格

本节包含一个名为GridExample的规则示例,它创建了两个标记,这两个标记在CSP页面上创建了一个信息表。

  • <GRID> tag

  • <GRIDDATA>tag

Grid Rule Definition

<csr:rule name="GridExample" match="GRID">
<csr:action>
<script language =Cache runat=compiler>
    Set maxrows=##this.GetAttribute("COLS")
    Set maxcols=##this.GetAttribute("ROWS")
    Do ..WriteText("<TABLE>",1)
    Set GRIDDATA=""
    ;Get Grid Data
    Set count=##this.Children.Count()
    For i=1:1:count {
         Set el=##this.Children.GetAt(i)
         Set tagname=el.TagName
         If tagname="GRIDDATA" {
             Set value=el.GetAttribute("VALUE")
             Set col=el.GetAttribute("COL")
             Set row=el.GetAttribute("ROW")
             Set GRIDDATA(row,col)=value
         }
    }
    ; Write Grid Elements
    For row=1:1:maxrows {
        Do ..WriteText("<TR>",1)
        For col=1:1:maxcols {
            Set d=$G(GRIDDATA(row,col))
            Do ..WriteCSPText("<TD>"_d_"</TD>",1)
        }
    }
    Do ..WriteText("</TR>",1)
    Do ..WriteText("</TABLE>",1)
</SCRIPT>
</csr:action>
</csr:rule>

虽然<GRIDDATA>属性在<GRID>的规则定义中被处理,但仍然需要一个空规则来实例化<GRIDDATA>标记:

<csr:rule name="GridDataExample" match="/GRID/GRIDDATA">
<csr:description>
This purpose of this empty rule is to instantiate the GRIDDATA tag
into the Document Object Model.
</csr:description>
<csr:action>
<csr:default>
</csr:action>
</csr:rule>

Generated Grid Class

上述规则定义编译成以下两个类:

  • Grid
  • GridData
Import User

Class csr.csp.GridExample Extends %CSP.Rule
{

Parameter CSRURL = "/csp/user/GRIDEXAMPLE.CSR";

Method CompilerMethod1() [ Language = cache ]
{
     Set maxrows=##this.GetAttribute("COLS")
     Set maxcols=##this.GetAttribute("ROWS")
     Do ..WriteText("<TABLE>",1)
     Set GRIDDATA=""
     ;Get Grid Data
     Set count=##this.Children.Count()
     For i=1:1:count {
         Set el=##this.Children.GetAt(i)
         Set tagname=el.TagName
         If tagname="GRIDDATA" {
             Set value=el.GetAttribute("VALUE")
             Set col=el.GetAttribute("COL")
             Set row=el.GetAttribute("ROW")
             Set GRIDDATA(row,col)=value
         }
     }
     ; Write Grid Elements
     For row=1:1:maxrows {
         Do ..WriteText("<TR>",1)
         For col=1:1:maxcols {
             Set d=$G(GRIDDATA(row,col))
             Do ..WriteCSPText("<TD>"_d_"</TD>",1)
         }
     }
     Do ..WriteText("</TR>",1)
     Do ..WriteText("</TABLE>",1)
}

Method RenderStartTag() As %Status
{
 New element Set element=##this
 Set %statuscode=$$$OK Do ..CompilerMethod1()
 Quit:$$$ISERR(%statuscode) %statuscode
 Quit $$$SKIPCHILDREN
}

}

GridData Class

Import User

Class csr.csp.GridDataExample Extends %CSP.Rule
{

Parameter CSRURL = "/csp/user/GRIDEXAMPLE.CSR";

Method RenderEndTag() As %Status
{
 New element Set element=##this
 Do ..RenderDefaultEndTag()
 Quit $$$OK
}

Method RenderStartTag() As %Status
{
 New element Set element=##this
 Do ..RenderDefaultStartTag()
 Quit $$$PROCESSCHILDREN
}

}

Using the Grid Rule

网格规则现在可以用在CSP页面的正文中:

<html>
<head>
<title>Grid Example</title>
</head>
<body>
<grid cols="5" rows="5">
<griddata value="Cell-1-1" col="1" row="1">
</griddata>
<griddata value="Cell-2-1" col="2" row="1">
</griddata>
<griddata value="Cell-2-2" col="2" row="2">
</griddata>
<griddata value="Cell-2-3" col="2" row="3">
</griddata>
<griddata value="Cell-2-4" col="2" row="4">
</griddata>
<griddata value="Cell-2-5" col="2" row="5">
</griddata>
<griddata value="Cell-3-1" col="3" row="1">
</griddata>
<griddata value="Cell-4-1" col="4" row="1">
</griddata>
<griddata value="Cell-4-3" col="4" row="3">
</griddata>
<griddata value="Cell-5-1" col="5" row="1">
</griddata>
<griddata value="Cell-5-5" col="5" row="5">
</griddata>
</grid>
</body>
</html>

Grid Rule Displayed Page

CSP页面现在显示以下内容:

  Cell-1-1 Cell-2-1 Cell-3-1 Cell-4-1 Cell-5-1
           Cell-2-2
           Cell-2-3          Cell-4-3
           Cell-2-4
           Cell-2-5                   Cell-5-5

原文地址:http://www.cnblogs.com/yaoxin521123/p/16910234.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性