2017-10-10 59 views

回答

0

它的JSON,直接查找關鍵。

var obj = { 'foo' : 'bar', 'fez' : [1,2,3], 'fizz' : { 'baz': true} }; 
 

 
console.log("'foo' is accessed like " + obj.foo + " -or- " + obj['foo']) 
 

 
var fw_table = {"FW_1":{ "tn":"sn_201", "cf": "06.57", "ci": "A1", "di":"048"}, "FW_2":{ "tn":"sn_202", "cf": "06.57", "ci": "A2", "di":"045"}}; 
 

 

 
function search(fwObj, key, val){ 
 
    var topKey = Object.keys(fwObj).find((e)=>{ return(fwObj[e][key] === val) }); 
 
    console.log(topKey); 
 
    return fwObj[topKey]; 
 
} 
 

 
console.log("Find cf:'06.57' : ", search(fw_table, "cf","06.57")); 
 
console.log("Find di:'045' : ", search(fw_table, "di","045"));