dart - Observable list not updating from js Callback -


i'm trying update template within js.callback. when cities.add("test") main() works fine , updates template string, doing same within callback template not updating. i'm trying use javascript api parse.com. login works , getting objects querys well. started out learning dart, maybe it's obvious i'm missing?

update: problem solved calling js.retain(parse) , dispatch() working solution below.

mydart.html :

<template iterate="city in cities"> {{city}} </template> 

mydart.dart :

import 'dart:html'; import 'package:web_ui/web_ui.dart'; import 'package:js/js.dart' js;  var parse = js.context.parse;  list<string> cities = new list();  void main() {    js.retain(parse); //solution problem (1/2)    parse.initialize("id", "key");    if(parse.user.current() == null) {      parse.user.login("user", "password",         js.map({           "success": new js.callback.once((user) => parsedata()),           "error": new js.callback.once((user,error) => print(error.message))         })     );   }   else     parsedata();    cities.add("hej"); }  void parsedata() {    //get cities   var city = parse.object.extend("city");   var query = new js.proxy(parse.query, city);   query.equalto(js.map({"acl" : parse.user.current()}));    query.find(     js.map({       "success": new js.callback.once((array){           (var i=0; < array.length; i++){           string cityname = array[i].get("name");           cities.add(cityname);           dispatch(); //solution problem (2/2)         }       }),       "error": new js.callback.once((object,error) => print(error.message))     })       ); } 

there seems 2 problems code :

  • you should call watcher.dispatch() after having updated list through callback.
  • the top level variable parse js.proxy used in callback. proxy has retained (with js.retain(parse)) used outside of current eventloop otherwise error js ref has been invalidated.

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -