|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
8 _( `2 @5 w( n3 w& S( I
4 \) v. F. v+ v3 J. X; g1 N5 b# S
7 A6 ~; n% o) ^# N% G# k! U Y3 c I" P0 T$ M1 G N, C% l! S
Technique 8 ~) L* D2 T3 n& o
There is no difference in setting up a query for a single Item or for many. Only the ; [* E2 x/ U1 M* `
criteria define the set size returned. In this recipe you create an Item and populate
; a% P1 U4 D0 W4 Cthe query criteria, apply it, and iterating over the Items returned producing a HTML ! r- T6 [! I O; S# H
<TABLE> fragment. , o5 s# D0 G" g& C( J8 b. B0 `0 G
2 A5 }. `$ g+ ?* j8 q; ~+ y' f2 a
0 L' M+ j; r2 y5 Z+ ^3 `. NJavaScript , s+ ]2 j/ n1 i7 g& Q! L+ k! E4 S6 S
var qryItem = this.newItem("Part","get"); 0 z7 e$ B3 B Q4 N: D8 C T. c
qryItem.setAttribute("select","item_number,description,cost");
/ ]' M! o: P. `( QqryItem.setProperty("cost", "100", "gt");
: t3 A8 _2 u/ h4 K# K* a& S8 tvar results = qryItem.apply(); ! Z X2 }' w2 q8 S2 K& ?
var count = results.getItemCount(); 6 P1 o3 b7 p$ ~: U, b( z& K h" I
var content = "<table>"; ( d8 O0 o+ O+ @* Y. Y l; L
for (var i=0; i<count; ++i)
6 v7 s! ]2 P2 R' i7 g P# V{
, I; _! \# t# W+ e' {) J var item = results.getItemByIndex(i); % \- K$ |5 L3 u
content += "" + $ c$ P/ o+ q2 I- y$ }, C
"<tr>" +
7 f6 A( ?+ N9 h W" n6 K: ` "<td>" + item.getProperty("item_number") + "</td>" +
, d! I/ B2 f1 K, Z8 ^1 d7 c "<td>" + item.getProperty("description") + "</td>" +
; E) f( A! X% M1 x "<td>" + item.getProperty("cost") + "</td>" +
$ b7 T9 P3 |! s" L$ r6 ^& t "</tr>"; 5 h8 P2 ~% b: m; O
}
" \8 ~. K* K: t# c! \' T7 icontent += "</table>";
4 H. h( O: @; Z# qreturn content; ; }. M) ?* c' T9 u/ R
0 A7 O3 d2 R& q) d, j1 @" A/ pC# - t( t9 h1 V+ r; N5 V! ]$ {/ n* U
Item qryItem = this.newItem("Part","get"); % Q) v1 f& s( t! u+ e- S0 j: ]- Q) I
qryItem.setAttribute("select","item_number,description,cost"); 3 Y& I( p6 Z3 S# j& F
qryItem.setProperty("cost", "100", "gt");
) p2 x/ i W6 e BItem results = qryItem.apply();
* \; u2 Y# r( J5 }int count = results.getItemCount();
# D T! _( \2 eint i; [ F" s' V) F: q: J
string content = "<table>";
1 n) @* [/ N: D3 afor (i=0; i<count; ++i)
. |6 ]* z9 s$ M{
# j+ y9 K. F2 \+ N% U Item item = results.getItemByIndex(i); 5 C8 u) ^' A) |" N1 J
content += "" + 1 E) l) W9 [# u
"<tr>" + # R$ Y& P/ {& A* I6 Z3 l
"<td>" + item.getProperty("item_number") + "</td>" +
: `( s9 K# u2 V% \( r "<td>" + item.getProperty("description") + "</td>" +
& `) w- w/ r8 s# E "<td>" + item.getProperty("cost") + "</td>" +
3 |, l7 [' j& C" ?5 n a; X, q- r- `! R "</tr>"; & o% ?5 g+ w) P1 v/ V
}
. [0 M; c7 m8 Z @9 [4 @1 p) }! Gcontent += "</table>"; 8 Z' Y) Y1 {4 V/ e8 S' l
Innovator innovator = this.newInnovator(); : K5 |1 k, l0 A: v
return innovator.newResult(content);
" b; b0 Q+ c3 \! s' z
: h+ H: n1 a' X6 J0 |VB.Net
: S* P; w9 h0 f* ~' l6 K; KDim qryItem As Item = Me.NewItem("Part","get") + |3 ~$ ?* V$ c4 P# D
qryItem.SetAttribute("select","item_number,description,cost") * r9 T: o9 J' R
qryItem.SetProperty("cost", "100", "gt") 1 [, I6 o: n T" X3 _) |- g
Dim results As Item = qryItem.Apply()
* S$ f: @( ]6 @& C( rDim count As Integer = results.GetItemCount() * }# @+ ?/ y+ b8 v _) k5 p
Dim i As Integer ; R0 n: o- H! h) B
Dim content As String = "<table>"
: c6 M/ w$ b w$ W9 P0 zFor i=0 to count - 1 " C+ A5 N; c4 j5 P1 }9 @$ l
Dim item As Item = results.GetItemByIndex(i) $ p! ~' D# t) f& y' K
content += "" + _
" s6 Y( e) b- ]! `7 j, X "<tr>" + _ 4 N& C( y# Y$ O/ c% K- P- Q
"<td>" + item.GetProperty("item_number") + "</td>" + _ * Q- P# A- [/ H
"<td>" + item.GetProperty("description") + "</td>" + _
4 u9 S' G1 u4 R* l# D "<td>" + item.GetProperty("cost") + "</td>" + _ * f+ A, }+ s; \+ o' v
"</tr>" 5 G) n& f& p" E. ^
Next ( T6 U7 O9 R: q0 R
content += "</table>" 4 I. ^( _# U# ~: J$ q! U' D3 \, D
. }. }6 {; k! YDim innovator As Innovator = Me.NewInnovator() % F% ^' Z' Z: J, C
return innovator.NewResult(content)
2 y( _- w9 A4 o: E6 S9 Y' Q( g) ] U! D; O9 b
8 m9 d, V# s& @$ b' Z1 C; |( Q
|
|