2011-03-24 148 views
1

我已經創建的類查找對象的數組對象具有相同的ID

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; 

    }); 

我單位的陣列,我想找到一個具有ID喜歡我element._unit_id。用Dojo做這件事很熱嗎?我正在查看文檔示例,但有dojo.filter我無法傳遞參數。任何人都可以幫忙嗎?

+0

你什麼時候開始閱讀道場的文檔,而不是請求的基本問題,循環順序? – 2011-03-25 05:07:17

回答

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 
} 

Test page for you

相關問題