0

当尝试查询数据库中的各种记录时,使用下面的数组,TaffyDB 将无法正确查找记录。从语法上讲,它似乎是合理的,应该查询并返回记录的值,但我认为我错过了一些致命的点。

$(".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
    }
  }
});

4

1 回答 1

0

使用

 part = r[parts[i]];

代替

part = r.parts[i]

解决语法错误。

于 2016-01-22T14:33:45.530 回答