Dart编译为JS但对象表示法不起作用

时间:2013-12-22 09:05:23

标签: dart polymer dart2js

我创建了一个Dart应用程序并从某些天气API源获取天气信息。

出于好奇,我想测试是否可以将天气信息封装在对象中,然后在Polymer模板中渲染对象的属性。

代码片段是这样的:

HTML文件:

<polymer-element ...>
  <template>
    Today in {{weather.city}}, the temperature is {{weather.temp}}. 
  </template>
</polymer-element>

和Dart文件:

@published Weather weather;
...
weather=new Weather.created(a_json_string);

class Weather
{
   String city;
   num temp;

   // The constructor just creates an instance by extracting the city, temp info fromthe JSON string
}

在Dartium中,它的效果非常好。

但是,如果我发布该应用程序并试图运行该输出HTML文件,它很糟糕:根本没有显示。

1 个答案:

答案 0 :(得分:1)

可能发生树木震动正在使你的田地掉落。 当字段仅由标记树中的聚合物表达式引用时,抖动无法识别需要的字段,因此它会丢弃它们。

我认为您仍然希望使用@observable,否则价值更改不会反映在您的视图中。

class Weather
{
   @observable String city; // or @reflectable String city;
   @observable num temp; // or @reflectable num temp;

   // The constructor just creates an instance by extracting the city, temp info fromthe JSON string
}