随笔 - 6, 文章 - 1, 评论 - 13, 引用 - 0
数据加载中……

SmartClient中Criteria 和 AdvancedCriteria的理解

时间不早了,就少写一些了。

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 ResultSets via ResultSet.applyFilter().

Client- and server-side systems built into SmartClient understand two criteria formats by default: simple key-value pairs (Criteria) or the AdvancedCriteria format.

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:

 var criteria = {     field1 : "value1",     field2 : ["value2", "value3"]  }  
Would select all records where field1 has value "value1" and where field2 has either "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
 sent to the SmartClient server, the Java representation of the criteria is described here. When sent to other servers, the operationBinding.dataProtocol affects the format.

格式相当简单。注意前面字段field1,是不需要将引号的.

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.

SmartClient DataSources can use AdvancedCriteria to search a list of Records, and the SmartClient Java Server can translate AdvancedCriteria to either SQL or Hibernate queries (Note: The server-side AdvancedCriteria handling feature is only available with the Power and Enterprise Editions of SmartClient; the Pro Edition is limited to ordinary criteria handling on the server side).可惜Power版和Enterprise版都老贵老贵的,企业版的都有按CPU卖的了,晕倒。

If the entire dataset is cached locally, SmartClient can perform AdvancedCriteria filtering on the client, avoiding a server call.

An AdvancedCriteria is an ordinary JavaScript object which can be created directly with JavaScript literal notation. For example:

var advancedCriteria = {
_constructor:"AdvancedCriteria",
operator:"and",
criteria:[
// this is a Criterion
{ fieldName:"salary", operator:"lessThan", value:"80000" },
{ operator:"or", criteria:[
{ fieldName:"title", operator:"iContains", value:"Manager" },
{ fieldName:"reports", operator:"notNull" }
]
}
]
}
An AdvancedCriteria is in effect a Criterion that has been marked with _constructor:"AdvancedCriteria" to mark it as complete criteria.

posted on 2011-10-24 23:08 风清扬 阅读(381) 评论(0)  编辑  收藏 所属分类: SmartClient


只有注册用户登录后才能发表评论。


网站导航: