|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 v3 w5 {; \) ~' w. f* y' r
7 D* c$ B2 K0 v$ P- O, C# q7 Y" q
6 J( n0 p$ }3 Z! X/ T9 z0 b6 q4 z9 b) L1 S5 b. a ^+ L2 `
Technique
8 B# q r! f# S5 s0 F3 Q5 eThere is no difference in setting up a query for a single Item or for many. Only the
/ n- k8 x! ]: _1 Zcriteria define the set size returned. In this recipe you create an Item and populate
3 ?& y. Y) |/ s) N, Z& pthe query criteria, apply it, and iterating over the Items returned producing a HTML - ]1 q# Y9 _: p/ D w
<TABLE> fragment.
" ?3 ~* W7 E9 X+ n3 k4 k% ^9 ]9 L0 A2 o: k
9 C/ b1 [+ p4 N: J& h" ~& D
JavaScript
5 l+ Z$ P. R/ Y3 ]$ k gvar qryItem = this.newItem("Part","get"); " Y. l+ W H6 B; V
qryItem.setAttribute("select","item_number,description,cost"); * W5 B# m P/ K8 }1 x4 H+ d0 o/ ^8 |
qryItem.setProperty("cost", "100", "gt"); ; ^6 m [2 `" b2 S! W2 C- G( C
var results = qryItem.apply();
1 U- N# F( Z" L' }var count = results.getItemCount();
$ E/ W) {+ f+ P5 ?. ?var content = "<table>";
/ G5 N" m; m" C( @8 G K# w; C3 ^1 Ffor (var i=0; i<count; ++i) 8 }, s# h* _1 \/ a; B' [" F# X
{ d% j- r% K. d+ U8 B! G+ ^
var item = results.getItemByIndex(i);
. z) v b7 } S' p$ `0 v content += "" + ; m! g: W/ P' D/ M5 }
"<tr>" + 5 [$ }4 \* ~1 q$ a$ l/ x& A
"<td>" + item.getProperty("item_number") + "</td>" + 7 f/ v2 ?' Z* I) t, ~# q2 z
"<td>" + item.getProperty("description") + "</td>" + $ Y9 X6 b; B! H; Y1 p! a! r
"<td>" + item.getProperty("cost") + "</td>" + ) z8 P' X# }6 Y& ?( m
"</tr>";
* J" a, [( L; ?' w: y} " J4 G& i$ v" J
content += "</table>"; * H( B% }; b; h! @
return content;
+ c: e2 q( b% ~0 T* ] : L) b5 Y( ~) G3 E( o
C# % T: ~4 h2 Z v# r) o) C, {
Item qryItem = this.newItem("Part","get");
" M! D4 j* G9 E7 I$ IqryItem.setAttribute("select","item_number,description,cost"); ; t% k" d# Y/ h, w) K5 w
qryItem.setProperty("cost", "100", "gt");
6 G2 H- N" s+ W1 s5 d x6 SItem results = qryItem.apply();
9 D2 F$ F V d0 U, Jint count = results.getItemCount();
6 ^3 y' D5 J4 N1 M- Mint i;
: h2 t3 W- C; W# l: [ c' [string content = "<table>"; 1 V" }& U8 ^9 y& J; Z
for (i=0; i<count; ++i) , D( V. m7 e/ W F% X
{
" ~% F. }; V/ H# j5 ~+ S+ R! n Item item = results.getItemByIndex(i);
: @; Q/ O0 i. O! W content += "" +
+ W! n: s9 _' k/ x# c5 q "<tr>" +
7 W4 \3 w) \& Z' {2 U "<td>" + item.getProperty("item_number") + "</td>" + + X% ^# Y r6 _" L
"<td>" + item.getProperty("description") + "</td>" + " B1 X2 F$ P1 `# w; I
"<td>" + item.getProperty("cost") + "</td>" +
5 F& t$ V+ {; u& H "</tr>"; ' K; S% f& w+ ?* T" M" K6 Z+ T
} 5 m+ H7 _7 S, ?* t4 Z- [( @
content += "</table>"; ! K ~4 ^1 e2 f" Y
Innovator innovator = this.newInnovator(); 9 A, b8 E4 U- G
return innovator.newResult(content);
0 U) B6 u# I3 p% Z' e" r* m
' X V& {) w6 e1 G/ `4 OVB.Net
9 f) F q3 G& m& UDim qryItem As Item = Me.NewItem("Part","get") ! T1 K) k& E x8 k' t; f
qryItem.SetAttribute("select","item_number,description,cost")
' c# L, U$ u6 \% wqryItem.SetProperty("cost", "100", "gt") 1 {; z; r, i4 Y/ D. k
Dim results As Item = qryItem.Apply()
1 ]+ E2 j+ ~; ~' r6 F: hDim count As Integer = results.GetItemCount()
2 ?" Q- J4 Z6 s, K ?8 Y/ bDim i As Integer
9 f) H1 b1 w3 b' _Dim content As String = "<table>" : m, Y x* W& Z
For i=0 to count - 1 + x$ q( L% ?2 R; M7 x9 G- c1 ~
Dim item As Item = results.GetItemByIndex(i) ; V& g# L# C" y6 h( ?' s
content += "" + _
1 i: A U/ G& L& n' @; `0 [: L "<tr>" + _ ' _/ k9 F [' ]: M% i8 b! a1 \
"<td>" + item.GetProperty("item_number") + "</td>" + _
8 H. r$ V% d5 S! \# } "<td>" + item.GetProperty("description") + "</td>" + _
: h+ Z7 A; H# b' F) H$ A "<td>" + item.GetProperty("cost") + "</td>" + _ $ s% w1 b c; \+ `9 a; y2 u! F) L
"</tr>" ) E7 Z3 C. G0 z8 [; t, V
Next & u7 \- t' ~1 w3 L- b' F2 n- F% u
content += "</table>"
* d" s1 ` C* ?
% k, v2 I2 G' ^" A" E4 _" aDim innovator As Innovator = Me.NewInnovator()
3 j) R0 E" q& p( b6 Freturn innovator.NewResult(content)
* j* M+ U2 t9 K) f6 M# X" S+ M: t7 ]! n+ q6 c; s% f; R
3 f3 G& q8 k2 }) z$ v- A |
|