简体   繁体   English

Dojo FilteringSelect加载数据

[英]Dojo FilteringSelect load data

I have the following code below, which will create a FilteringSelect and set the first selected item: 我在下面有以下代码,它将创建一个FilteringSelect并设置第一个选定的项目:

// Store initialization:
var jsonStore = custom.store.JsonRest({ ... });
var memoryStore = dojo.store.Memory();
var myStore = dojo.store.Cache( jsonStore, memoryStore);
var dataStore = custom.store.MyObjStore({ objectStore: myStore, ...  });

// FilteringSelect initialization:
var fsel = new dijit.form.FilteringSelect({
             id: 'fsel',
             searchAttr: 'id',
             store: dataStore
           });

// Setting the first item on FilteringSelect, retrieved from store objects
fsel.store.fetch({ query: {id:""},
  onComplete: function (items, request) {
    var val = "";
    if (items.length>0) val = items[0].id;
    fsel.set('value', val);
  }
});
  1. First problem is that, if the items[0].id = 0 , this item is not set on FilteringSelect. 第一个问题是,如果items[0].id = 0 ,则此项目未在FilteringSelect上设置。

  2. fsel.store.fetch({ ... }) queries the server, which is ok. fsel.store.fetch({ ... })查询服务器,这没关系。 The problem is that the retrieved items are not kept in memory, or they are, but are not retrieved by FilteringSelect on the next event. 问题是检索到的项目不会保留在内存中,或者它们是,但在下一个事件中不会被FilteringSelect检索。 I mean, when I click the first time on FilteringSelect's dropdown another query is sent to server to get the items, the following times they get from memory. 我的意思是,当我第一次点击FilteringSelect的下拉列表时,会向服务器发送另一个查询以获取项目,以下时间是从内存中获取的。

Could anyone help me to solve these two problems? 谁能帮我解决这两个问题?

Note: I'm using Dojo version 1.7.2 (27913). 注意:我使用的是Dojo 1.7.2版(27913)。

After a talk with someone from dojo, I solved my question the following way: 在与道场的某人谈话后,我通过以下方式解决了我的问题:

  1. Switching to the last version ( 1.8.1 ), fixed this first issue. 切换到上一个版本( 1.8.1 ),修复了第一个问题。

  2. Using the memoryStore on FilteringSelect, instead of cache store ( myStore ), will just make use of objects in memory. FilteringSelect上使用memoryStore而不是缓存存储( myStore ),只会使用内存中的对象。 Making a query on myStore (cache store) will load the objects from server to memory. myStore (缓存存储)上进行查询会将对象从服务器加载到内存。

// Store initialization:
var jsonStore = new JsonRest({ ... });
var memoryStore = new Memory();
var myStore = new Cache(jsonStore, memoryStore);
// Note: ObjectStore was removed.

// FilteringSelect initialization:
var fsel = new FilteringSelect({
         id: 'fsel',
         searchAttr: 'id',
         store: memoryStore
       });

// Setting the first item on FilteringSelect and loading items to memory
when (myStore.query({id:""}),
  function (items, request) {
    var val = "";
    if (items.length>0) val = items[0].id;
    fsel.set('value', val);
  }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM