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

第五十三章 开发自定义标签 - 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调用。

创建标记以显示表格

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

  • tag

  • tag

Grid Rule Definition






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



This purpose of this empty rule is to instantiate the GRIDDATA tag
into the Document Object Model.





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("",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("",1)
         For col=1:1:maxcols {
             Set d=$G(GRIDDATA(row,col))
             Do ..WriteCSPText("",1)
         }
     }
     Do ..WriteText("",1)
     Do ..WriteText("
"_d_"
",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页面的正文中:



Grid Example




























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

你可能感兴趣的:(第五十三章 开发自定义标签 - Using csr %cspQuote Methods)