我创建了课程
dojo.declare("UNIT",null,{
_id:'',
constructor:function(i){
this._id=i;
});
和
dojo.declare("ELEMENT", null, {
_id:'',
_unit_id:'',
constructor:function(u,i){
this._unit_id=u;
this._id=i;
});
我有单位数组,我想找到一个像我的element._unit_id一样的id。很高兴用Dojo做到这一点?我正在查看文档示例,但有dojo.filter我无法传递参数。有人可以帮忙吗?
答案 0 :(得分:2)
您可以使用dojo.filter.E.g:
var units = [{
id: 1,
name: "aaaa"
},
{
id: 2,
name: "bbbb"
},
{
id: "2",
name: "cccc"
},
{
id: "3",
name: "dddd"
}];
var currentElementId = 2;
var filteredArr = dojo.filter(units, function(item) {
return item.id==currentElementId;
});
// do something with filtered array
}