%cspQuote
例程定义包含两个不同引用方法的定义。
Quote
QuoteCSP
Quote Method
$$Quote^%cspQuote(line As %String)
用引号将输入字符串括起来。
QuoteCSP Method
$$QuoteCSP^%cspQuote(line As %String)
用引号将输入字符串括起来,并解析#()#
、##()#
、##''#
、#server
和#url
调用。
标记以显示表格本节包含一个名为GridExample
的规则示例,它创建了两个标记,这两个标记在CSP
页面上创建了一个信息表。
tag
tag
<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("",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(""_d_" ",1)
}
}
Do ..WriteText(" ",1)
Do ..WriteText("
",1)
</SCRIPT>
</csr:action>
</csr:rule>
虽然
属性在
的规则定义中被处理,但仍然需要一个空规则来实例化
标记:
This purpose of this empty rule is to instantiate the GRIDDATA tag
into the Document Object Model.
上述规则定义编译成以下两个类:
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(""_d_" ",1)
}
}
Do ..WriteText(" ",1)
Do ..WriteText("
",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
}
}
网格规则现在可以用在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>
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