mica
mica

Reputation: 4308

How to call jquery´s $ function in dart

I try to make the following jquery functioncall in dart

$('#mytable').handsontable({
      data: data,
      minSpareRows: 1,
      colHeaders: true,
      contextMenu: true
    });

my dartcode

import 'dart:js';

void main() 
{ var data = [["", "Maserati", "Mazda", "Mercedes", "Mini", "Mitsubishi"],
              ["2009", 0, 2941, 4303, 354, 5814]  ];

  context.callMethod('$', ['#mytable'])
  .callMethod('handsontable', [new JsObject.jsify(
  {'data': data,
   'minSpareRows': 1,
   'colHeaders': true,
   'contextMenu': true})]);  
}

The line:

  context.callMethod('$', ['#mytable'])

produces an error in the editor: Expected an identifier ('$' is marked red) Any other string then the '$' semes to be ok, but the jquery function in $()

Upvotes: 1

Views: 243

Answers (2)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76353

You get the error because $ is the character in Dart String to perform String interpolation. To make your code work you have to escape this character context.callMethod('\$', ['#mytable']) or use a raw String context.callMethod(r'$', ['#mytable']).

Upvotes: 2

mica
mica

Reputation: 4308

thx @Intelekshual

context.callMethod('jQuery', ['#mytable'])
  .callMethod('handsontable', [new JsObject.jsify(
  {'data': data,
   'minSpareRows': 1,
   'colHeaders': true,
   'contextMenu': true})]);

works fine.

Upvotes: 0

Related Questions