Search code examples
javascriptjquerydatabasetaffydb

TaffyDB not querying record


When trying to query a variety of records in the database, using the below array, TaffyDB will not lookup the record correctly. Syntactically, it appears to be sound and should query and return the value of the record, but I assume I'm missing some fatal point.

$(".cat").each(function(){
  $this = $(this);
  var db = ($this.data("category")).toString()
  var fn = window[db];
  if (typeof fn === "function") fn().each(function(r){
    var parts = ["cpu", "mobo", "ram", "gpu", "sc", "hdd", "ssd", "psu", "case", "cooler", "os"];
    var pmup = "";
    for(i=0;i<parts.length;i++){
      var part = r.parts[i];
      console.log(part) // returns: Uncaught TypeError: Cannot read property '0' of undefined
    }
  }
});


Solution

  • Using

     part = r[parts[i]];
    

    instead of

    part = r.parts[i]
    

    solves the syntax error.