dstore(dojo)事件(添加)在集合上失误

时间:2015-06-06 18:58:27

标签: javascript dojo dstore

道场版:1.10.0

dstore版本:1.1.0

遵循的步骤。

1)使用dstore内存(employeeStore)创建了一个内存存储。

2)通过应用创建集合salesEmployee     filter。我,e employeeStore.filter({department:'sales'});

3)在add集合上添加了salesEmployee事件监听器。

4)向部门employeeStore添加了新员工     会计,即employeeStore.add({name:'William', department:'accounting'});

即使add事件侦听器附加到salesEmployee事件侦听器,它也会触发     salesEmplyoee集合。

根据我的理解,事件监听器不应该触发,因为员工属于会计部门,并且监听器附加到require({ packages: [ { name: 'dstore', location: '//cdn.rawgit.com/SitePen/dstore/v1.1.0' } ] }, [ 'dojo/_base/declare', 'dstore/Memory', 'dojo/domReady!' ], function(declare, DMemory ) { var employees = [ { name:'Jim', department:'accounting'}, { name:'Bill', department:'engineering'}, { name:'Mike', department:'sales'}, { name:'John', department:'sales'} ]; var employeeStore = new DMemory( {data:employees, idProperty: 'name'}); var salesEmployees = employeeStore.filter({department:'sales'}); salesEmployees.on('add', function(event){ alert(JSON.stringify(event.target)); }); employeeStore.add({name:'William', department:'accounting'}); }); 集合。

这是jsfiddle

<dependency>
    <groupId>org.jbehave</groupId>
    <artifactId>jbehave</artifactId>
    <version>4.0</version>
</dependency>

我的理解是否正确?

1 个答案:

答案 0 :(得分:1)

集合通常从它们来自的商店继承add / put / remove方法。当dstore触发事件时,将通知与该存储相关的所有集合。这主要是为了保持一致性,因为在存储是基于服务器的情况下,根据其范围/过滤器/排序标准,不可能完全确定客户端是否每个事件都适用于每个集合。不可否认,对于可以可行地过滤事件的简单情况,最一致的并不总是最方便。

如果您要使您的内存存储可跟踪(使用dstore/Trackable)并监听已跟踪的集合,您应该能够通过选中event.index来区分与您的过滤器匹配的项目的事件event.previousIndex(对于过滤掉的项目,undefined都是var TrackableMemory = declare([ Memory, Trackable ]); var store = new TrackableMemory({ data: ... }); var collection = store.filter(...).track(); collection.on(...);

Options -Indexes +FollowSymLinks    
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} !/artist/ [NC]
RewriteRule ^(.*)$ artist/$1 [L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f 

<IfModule mod_php5.c>  
    RewriteRule ^(.*)$ index.php/$1 [L]    
</IfModule>    

# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>    
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>