道场版本:1.10.0
dstore 版本:1.1.0
遵循的步骤。
1) 使用 dstore 内存 ( employeeStore
) 创建了内存存储。
salesEmployee
2)通过应用
filter
.i,e创建一个集合employeeStore.filter({department:'sales'});
3)在集合上添加了add
事件监听器。salesEmployee
employeeStore
4)在部门
会计中添加了一个新员工,即employeeStore.add({name:'William', department:'accounting'});
add
即使事件侦听器附加到
salesEmployee
集合,它也会触发。
根据我的理解,事件侦听器不应触发,因为该员工属于会计部门并且侦听器附加到salesEmplyoee
集合中。
这是jsfiddle。
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'});
});
我的理解正确吗?