我有一個json數據。Jquery代碼從數組中找到重複的信息
data ={{"id":"10","name":"test"},{"id":"10","name":"test1"},{"id":"11","name":"tsst"},{"id":"41","name":"jhkj"},{"id":"11","name":"yuyyu"},}
從JSON數據我正在讀取的ID從數據庫表中獲取location
如下
data.each(function(index) {
var id = index.id //gets 10
//again gets 10 and again doing db operations for same id value
//db operations
//get location details from db using this id
// operations after getting locations....................
});
我proble是id
重複即10,10,11,41 ,11
。所以呼籲db
操作重複值也。我如何通過調用數據庫操作重複的id值來避免。
您忘記從'data'添加測試ID的到'dup'陣列。 – stUrb
@stUrb謝謝我得到它並修復它。 –