|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" U' N; @5 P2 f! F5 ~5 [/ @. V' |- k' V4 o
]1 l* f$ t \- h1 L$ ?
9 x( o6 a* u* N, F5 ^5 L5 _
Technique
* w; M! o$ B- t1 ?: m% XThere is no difference in setting up a query for a single Item or for many. Only the # I4 @2 R1 Y/ [) |
criteria define the set size returned. In this recipe you create an Item and populate
! X' _, t0 w, J. _/ e9 zthe query criteria, apply it, and iterating over the Items returned producing a HTML ; a( D! S; o8 Z5 ~3 H- v
<TABLE> fragment. ) b* _0 H8 D8 H0 k( I& O4 }
) R |, J. E7 C$ n- h0 e# {0 G2 V; t# z y
JavaScript . F0 @( x; X7 R
var qryItem = this.newItem("Part","get"); 0 _4 B" i; S+ g6 Y4 W
qryItem.setAttribute("select","item_number,description,cost");
, l, n! w0 W- S7 E1 wqryItem.setProperty("cost", "100", "gt");
8 {- @. R) ?+ `! G4 `var results = qryItem.apply();
/ |$ }: h* q/ h" \: k: j5 \1 ]0 L. ^var count = results.getItemCount();
9 ^6 ]+ p8 H, E' [- d! D2 Cvar content = "<table>"; * d& r, G1 X8 z' s8 g
for (var i=0; i<count; ++i)
' _) u+ Z3 c8 F4 z1 x& I& w{
8 p: d. T0 A% y6 V var item = results.getItemByIndex(i); 0 b+ z q$ [ P3 H
content += "" + 1 F; r( u" x9 k
"<tr>" + 2 G2 a7 k( K' [$ P$ L
"<td>" + item.getProperty("item_number") + "</td>" + ! E; b2 J4 [* J" n- ?' Q% \
"<td>" + item.getProperty("description") + "</td>" +
5 @7 ]3 ^9 F C8 ?6 ~ "<td>" + item.getProperty("cost") + "</td>" + : H- f: m6 t/ G5 J
"</tr>"; / _& ?4 R& {; k( N+ a
} ; }2 W* J4 P' I' M0 d7 H
content += "</table>";
4 N4 H- {$ E& g1 e. oreturn content; 1 H* |$ S7 D4 H0 Y$ g( w+ Q9 l& a
8 |6 {9 p/ q7 L- Y4 ^- H
C#
( G( Z- ?* L# Z8 S" M" H; s) ^) aItem qryItem = this.newItem("Part","get");
% _2 g {+ I9 a' kqryItem.setAttribute("select","item_number,description,cost");
& c1 y, N$ w6 t& K( MqryItem.setProperty("cost", "100", "gt");
: `% ^( M" p, n& P- WItem results = qryItem.apply();
' C5 @, _, L; {1 dint count = results.getItemCount();
- m/ a6 Q* Z5 B6 F+ \2 sint i; * e) Q# h/ Q6 R) a
string content = "<table>";
5 `) h; a3 j* t- g" S1 r& Vfor (i=0; i<count; ++i) ; H# |3 |! Q) x+ B! @# c
{
' s g" l# J9 g; D2 x# v, w) k( \ Item item = results.getItemByIndex(i); " D5 g* P4 W4 L( |
content += "" +
2 q* g, }2 m' P( J& b "<tr>" +
( p; o" r# J$ _9 ` "<td>" + item.getProperty("item_number") + "</td>" + 6 `: b5 q% T3 y' x8 V
"<td>" + item.getProperty("description") + "</td>" +
/ }( T( _3 F& J9 j9 c' O "<td>" + item.getProperty("cost") + "</td>" +
) x- p# }, x9 ^7 I/ \# G "</tr>";
5 i2 U& Z: @+ u# q} U( \$ u# }' s F: j$ _! u; a
content += "</table>";
+ B2 Q Q8 r# t' E5 BInnovator innovator = this.newInnovator(); , R$ F; N4 F0 Q2 i! r4 A2 \
return innovator.newResult(content);
9 K) @& p% N9 N" l & F7 y7 k$ _3 }- J3 x
VB.Net 6 H; j% T. Z/ ]0 X: L2 U" i
Dim qryItem As Item = Me.NewItem("Part","get") 6 ?& H6 P' b+ F" _
qryItem.SetAttribute("select","item_number,description,cost")
7 @7 f. g; h" g' ~8 o" gqryItem.SetProperty("cost", "100", "gt")
2 e& i! ^; ^, D4 L6 S6 WDim results As Item = qryItem.Apply()
+ ?" D8 q, v6 e3 O# o1 W) FDim count As Integer = results.GetItemCount() 3 T$ ^3 O$ L5 w7 [/ j' ]
Dim i As Integer
/ @# B# B& H R6 G5 W7 NDim content As String = "<table>"
8 j) b* j3 G! rFor i=0 to count - 1
8 I% d4 Z& V8 o$ s& A5 ]' n* q Dim item As Item = results.GetItemByIndex(i)
K _9 L. R3 t6 l- s8 l content += "" + _
' X$ ~0 O! U k% m. f1 ?$ p6 x "<tr>" + _ . Q" U2 D8 }5 N4 p+ W% x
"<td>" + item.GetProperty("item_number") + "</td>" + _
7 r T/ i% b u7 r* e8 j" ~ "<td>" + item.GetProperty("description") + "</td>" + _
' `! E( D8 `; P "<td>" + item.GetProperty("cost") + "</td>" + _ 6 j) r; S5 a' q6 S
"</tr>" : m' n& O9 T5 m
Next 3 f. V P. s2 ^
content += "</table>" 8 G6 V' v1 ]; \
: X. R+ m, [ A, l& gDim innovator As Innovator = Me.NewInnovator() ' z# D$ K; v9 g4 k. [: o6 S6 F: }
return innovator.NewResult(content) 0 l3 B1 c" M' j( b3 a
3 L! X9 G1 Q5 u2 i
$ l! d4 N3 R9 y: P" }: C, H; r7 I
|
|