javascript - 从 fetch 回调中调用的 Polymer notifyPath
问题描述
我的应用程序有财产
myData: {
type: Array,
},
初始化为:
[{'company_name': 'Company 1'}, {'company_name': 'Company 2'}]
从后端加载数据后,我需要在模板处触发 dom-repeat 更新数组。
<template is="dom-repeat" items="{{myData.countries}}" as="country">
<div>[[country.name]]</div>
</template>
我遇到的问题是 notifyPath 不适用于 fetch 方法,即:
var self = this;
fetch('/api/all')
.then(res => res.json())
.then(json => self.myData[1]['countries'] = json)
.then(function() {
// not work
self.notifyPath("myData.1.countries", self.myData[1]['countries']);
});
并且在 fetch 方法之外可以正常工作:
self.myData[1]['countries'] = [{'country_name': 'Albania'}, {'country_name': 'Mongolia'}];
self.notifyPath("myData.1.countries", self.myData[1]['countries']);
我在某个地方弄错了,还是应该以不同的方式做?
解决方案
推荐阅读
- node.js - 如何在 ClojureScript 中检查 Firestore 服务器时间戳的类型?
- python - 获取累积的唯一联系人
- javascript - 使用烧瓶、ajax 绘制传单后重新渲染页面
- swift - 状态栏样式更新有一些延迟
- c++ - 使用 INT32_MAX 时无法打印正确答案
- java - 我是第一次在 ES 上工作。我正在尝试将批量 json 文件上传到 java 中的新 Elasticsearch 索引中,但出现错误
- ios - 如何使用 CMMotionManager 知道设备向左/向右/向后或向前倾斜
- sql - 如何在 PL/SQL 中解决此过程
- google-bigquery - 如何从 geoJSON 文件中分离具有 NULL 值的记录?
- database - Cassandra:零默认 TTL 是什么意思?