如何使用每个函数,从jquery到Dart语言?

时间:2013-08-20 10:10:19

标签: dart dart-webui dart-editor dart-js-interop

我在jquery中有一个函数,如下所示

function findMax(){
 $( ".elements" ).each(function( ) {
  if($(this).css('z-index')>max1)
  max1=$(this).css('z-index');
  max1=parseInt(max1);
 });
}

我必须在Dart语言中实现此功能。在使用.each函数和'this'函数时遇到语法问题。

1 个答案:

答案 0 :(得分:8)

相当于jQuery:

$(".elements").each(function( ) {
  // do something with this being one of elements with a 'elements' class
  // you can access the current element with $(this)
});

在Dart中:

querySelectorAll('.elements').forEach((Element e) {
  // do something with e being one of elements with a 'elements' class
  // you can access the current element with e
});