1

I am trying to convert some Javascript code to Dart and I'm getting stuck.

This is the original code:

<div id="main" style="width: 100%; height: 400px;"></div>

<script type="text/javascript">
    // widget configuration
    var config = {grid: {name: 'grid'}}

    $(function () {
        // initialization
        $().w2grid(config.grid);

        w2ui['grid'].records.push({recid : i+1, personid: i+1});

        w2ui.grid.refresh();
        $('#main').w2render('grid');
    });
</script>

My dart code looks like this: html:

<div id="main" style="width: 100%; height: 400px;">

dart:

var grid = new JsObject.jsify({'name' : 'grid'});
var config = new JsObject.jsify({'grid' : grid});

js.context.callMethod(r'$', []).callMethod('w2grid', [config['grid']]);

var record = new JsObject.jsify({'recid' : i+1, 'personid' : i+1});
context['w2ui']['grid']['records'].callMethod('push', [record]);

context['w2ui']['grid'].callMethod('refresh');

var div = js.context.callMethod(r'$', ['#main']);
div.callMethod('w2render', [grid]);

I think most of it works until the final 2 lines where I am trying to call w2render on the "main" div. I'm not positive that up to that point works, I just know it isn't throwing any errors until those lines. Does anyone have any suggestions as to what I might be doing wrong?

Thanks.

4

0 回答 0