2
我有一个JSON文件(包含整数数组),我向其发送<iron-ajax>
请求并检索响应。我想处理响应(一个整数数组),并通过单击按钮将整数数组中的所有值递增1。递增JSON数组中所有元素的值并使用Polymer组件显示
<iron-ajax
url="/api/time-series/simple-data/4"
last-response="{{_simpleDataValuesA}}"
auto>
</iron-ajax>
<h1> /* Where I would like the entire updated array to be shown when I press the BUTTON to increment */
我的高分子定义:
Polymer({
is: 'new-page',
properties: {
_simpleDataValuesA: {
type: Object
},
_cal: {
type: Array,
computed: 'cal_incr(_simpleDataValuesA)'
}
},
cal_incr:function(_simpleDataValuesA){
var a = this._simpleDataValuesA.data.values[0];
a.forEach(function increment(item,index,a) {
a[index]+=1;
})
console.log('array -- >',a);
console.log('this._simpleDataValuesA.data.values[0] -- >',this._simpleDataValuesA.data.values[0]);
this._simpleDataValuesA.data.values[0]=a;
return this._simpleDataValuesA.data.values;
}
});
每次我按一下按钮,就应该由1
我的组件模板中增加价值我的JSON文件:
{
"id": 4,
"data": {
"labels": ["acvc","b","a","b","a"],
"values": [[112,57,53,122,128,120,56]]
}
}
非常感谢你这对我的作品! @ tony19 –
@AnkitaGavali没问题:) – tony19