网站大量收购独家精品文档,联系QQ:2885784924

dojostoreMemory 和 SimpleQueryEngine 解读.docx

  1. 1、本文档共14页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
dojostoreMemory 和 SimpleQueryEngine 解读

Example:require([dojo/store/Memory], function(Memory){var someData = [ {id:1, name:One}, {id:2, name:Two} ]; store = new Memory({data: someData}); store.get(1) - Returns the object with an id of 1 store.query({name:One}) // 根据特定的查询条件,返回符合要求的结果集。 store.query(function(object){return object.id 1; }) // 通过传递一个函数来进行查询,可以实现更复杂的查询操作 store.query({name:One}, {sort: [{attribute: id}]}) // 除了查询以外,返回的结果集会根据id来排序。 store.put({id:3, name:Three}); //保存{id:3, name:Three} 对象,并且放在id:3的位置。 store.remove(3); // 根据ID来删除对象});?  官方API的介绍和切合要点,Memory store的最显著的特点,就是“简单”。Memory store的功能就像上面的例子中的一样,简单暴力,基本齐全。下面我们根据dojo里的源码进一步解析:?构造函数constructor:  constructor: function(options){// summary:// Creates a memory object store.// options: dojo/store/Memory// This provides any configuration information that will be mixed into the store.// This should generally include the data property to provide the starting set of data.for(var i in options){this[i] = options[i]; }this.setData(this.data || []); },  嗯,我们通过new字段来创建memory store到对象时,就会调用到这里。案例中的options参数为{data:somedata}。实际上是创建了最最简单的Memory stortt仅仅只用了一个对象数组。所以当然咯,可以有略复杂一点的情况。代码中this[i]=options[i],可以看出各种配置都体现在Menory对象的属性里。下面列一下:  // data: Array// The array of all the objects in the memory store data:null,// idProperty: String// Indicates the property to use as the identity property. The values of this// property should be unique. idProperty: id,// index: Object// An index of data indices into the data array by id index:null,// queryEngine: Function// Defines the query engine to use for querying the data store queryEngine: SimpleQueryEngine,  data:是必须的,如果不存在,会被赋予一个[]空数组。  index:后续会提到这个属性,它是一个以id(idProperty) 为索引的表,表的数据是一个改id对应的属性在data数组里的序号索引。  idProperty:啊哈,通过这个属性我们可指定改memory的一个不可重复的标识符(字段名),默认是为id。  queryEngine:可以指定memory的搜搜引擎,默认使用的是dojo/store/util/SimpleQueryEngine。?setData: function(data){// summary:// Sets the given data as the

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档