Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (中间值)。则不是函数_Javascript_Ecmascript 6_Ecmascript 5 - Fatal编程技术网

Javascript (中间值)。则不是函数

Javascript (中间值)。则不是函数,javascript,ecmascript-6,ecmascript-5,Javascript,Ecmascript 6,Ecmascript 5,我对Javascript还是相当陌生的。 由于一些遗留系统的原因,目前我正在将一些ES6代码转换回ES5代码。 我转换了以下代码: $row.find('.gridCellDetailAction') .each((i, elem) => $translate('Grid.Show' + $(elem).attr('data-title') + 's') .then(trans => $(elem).attr('title', trans))); 对此 $row.find(

我对Javascript还是相当陌生的。 由于一些遗留系统的原因,目前我正在将一些ES6代码转换回ES5代码。 我转换了以下代码:

$row.find('.gridCellDetailAction')
 .each((i, elem) => $translate('Grid.Show' + $(elem).attr('data-title') + 's')
.then(trans => $(elem).attr('title', trans)));
对此

   $row.find('.gridCellDetailAction')
        .each(function (i, elem) {
              $translate('Grid.Show' + $(elem).attr('data-title') + 's')
   }.then(function (trans) { $(elem).attr('title', trans) }));
现在我得到以下错误:

(中间值)。则不是函数


现在我知道我对
做了一些错误,然后
。但是我怎样才能得到同样的结果呢?

怎么了:
我将从代码中删除
$row.find('.gridCellDetailAction').each()

这个代码似乎是错误的; 因此,我们需要在
函数()中放置
.then(function(trans){$(elem).attr('title',trans)})


完整代码:

$row.find('.gridCellDetailAction')
    .each(function (i, elem) {
        $translate('Grid.Show' + $(elem).attr('data-title') + 's')
            .then(function (trans) { $(elem).attr('title', trans) });
    });

只要稍加格式化,您就可以很容易地看到差异。 一次调用
然后
处理
$translate
的结果,另一次调用
然后
处理函数定义

$row.find('.gridCellDetailAction')
.each(
  (i, elem) => {
    $translate(
     'Grid.Show' + $(elem).attr('data-title') + 's'
    )
    .then(
      trans => $(elem).attr('title', trans)
    )
  }
);

巴贝尔能帮忙吗?我能看到一个紧括号
}
放在错误的地方,在
之前的那一个。然后
。那一个应该放在最后一个
之前。这没有多大帮助。你应该试着解释为什么他/她的代码不起作用,以及你做的与他/她的不同之处。很高兴我能够帮助你。您应该将此答案标记为正确,以便其他用户可以轻松找到它
$row.find('.gridCellDetailAction')
.each(
  (i, elem) => {
    $translate(
     'Grid.Show' + $(elem).attr('data-title') + 's'
    )
    .then(
      trans => $(elem).attr('title', trans)
    )
  }
);
$row.find('.gridCellDetailAction')
.each(
  function (i, elem) {
    $translate('Grid.Show' + $(elem).attr('data-title') + 's')
  }// <-- The error is here
  .then(
    function (trans) { 
      $(elem).attr('title', trans) 
    }
  )
);
$row.find('.gridCellDetailAction')
.each(
  function (i, elem) {
    $translate('Grid.Show' + $(elem).attr('data-title') + 's')
    .then(  //Now then is called on the result of $translate
      function (trans) { 
        $(elem).attr('title', trans) 
      }
    )
  }
);