﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-我问佛：如何才能如你般睿智？ 佛曰：佛是过来人，人是未来佛-随笔分类-SmartClient</title><link>http://www.blogjava.net/spy1988/category/49908.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 24 Oct 2011 15:15:43 GMT</lastBuildDate><pubDate>Mon, 24 Oct 2011 15:15:43 GMT</pubDate><ttl>60</ttl><item><title>SmartClient中Criteria 和 AdvancedCriteria的理解</title><link>http://www.blogjava.net/spy1988/archive/2011/10/24/361929.html</link><dc:creator>风清扬</dc:creator><author>风清扬</author><pubDate>Mon, 24 Oct 2011 15:08:00 GMT</pubDate><guid>http://www.blogjava.net/spy1988/archive/2011/10/24/361929.html</guid><wfw:comment>http://www.blogjava.net/spy1988/comments/361929.html</wfw:comment><comments>http://www.blogjava.net/spy1988/archive/2011/10/24/361929.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/spy1988/comments/commentRss/361929.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/spy1988/services/trackbacks/361929.html</trackback:ping><description><![CDATA[时间不早了，就少写一些了。<br /><div><p>Criteria for selecting only a matching set of records from a DataSource.  Criteria can  be applied on the client and server.  Unless configured otherwise, criteria will generally  be applied client-side by <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">ResultSet</a>s via <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">ResultSet.applyFilter()</a>.    </p><p>  Client- and server-side systems built into SmartClient understand two criteria formats by  default: simple key-value pairs (Criteria) or the <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">AdvancedCriteria</a> format.  </p><p>  Simple key-value Criteria are represented via a JavaScript Object where each property  specifies the name and required value for a field.  Multiple legal values for a field can be  provided as an Array.  For example:  </p><pre><span style="color: red;"> var criteria = {     field1 : "value1",     field2 : ["value2", "value3"]  }  </span></pre>  Would select all records where field1 has value "value1" and where field2 has <em>either</em>  "value2" or "value3".    When writing custom client and server-side filtering logic, criteria must be a JavaScript  Object but the properties of that Object can contain whatever data you want.  When<br />&nbsp;sent to  the SmartClient server, the Java representation of the criteria is described  <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">here</a>.  When sent to other servers, the  <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">operationBinding.dataProtocol</a> affects the format.</div><br />格式相当简单。<span style="color: red;">注意前面字段field1，是不需要将引号的</span>.<br /><div><p>AdvancedCriteria is a format for representing search criteria which may include  operators on field values such as "less than", or may include sub-clauses such as several   criteria applied to fields joined by an "OR" operator.  </p><p>  SmartClient DataSources can use AdvancedCriteria to search a list of <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">Record</a>s, and  the SmartClient Java Server can translate AdvancedCriteria to either SQL or Hibernate  queries (<strong style="color: red;">Note:</strong><span style="color: red;"> The server-side AdvancedCriteria handling feature is only available   with the </span><strong style="color: red;">Power</strong><span style="color: red;"> and </span><strong style="color: red;">Enterprise</strong><span style="color: red;"> Editions of SmartClient; the Pro Edition is   limited to ordinary criteria handling on the server side).可惜Power版和Enterprise版都老贵老贵的，企业版的都有按CPU卖的了，晕倒。</span></p><p>  If the entire dataset is cached locally, SmartClient can perform AdvancedCriteria filtering   on the client, avoiding a server call.  </p><p>    An AdvancedCriteria is an ordinary JavaScript object which can be created directly  with JavaScript literal notation.  For example:  </p><pre><div>var advancedCriteria = {<br />        _constructor:"AdvancedCriteria",<br />        operator:"and",<br />        criteria:[<br />            // this is a Criterion<br />            { fieldName:"salary", operator:"lessThan", value:"80000" },<br />            { operator:"or", criteria:[<br />                  { fieldName:"title", operator:"iContains", value:"Manager" },<br />                  { fieldName:"reports", operator:"notNull" }<br />              ]  <br />            }<br />        ]<br />    }</div></pre>  An AdvancedCriteria is in effect a <a href="http://localhost:8888/isomorphic/system/reference/SmartClient_Reference.html">Criterion</a> that has been marked with   _constructor:"AdvancedCriteria" to mark it as complete criteria.      </div><br /><img src ="http://www.blogjava.net/spy1988/aggbug/361929.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/spy1988/" target="_blank">风清扬</a> 2011-10-24 23:08 <a href="http://www.blogjava.net/spy1988/archive/2011/10/24/361929.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>