parse(new String[] { "foo", "bar", "baz" });
我正在从JSON文件加载数据并将其结构化为HTML表。我能够获取数据并构建它,但问题是它不会反映为HTML表,即插值不起作用。虽然变量带有各自的值。
答案 0 :(得分:4)
使用箭头函数来保持'this'的上下文不变。
reloadData() {
this._spservice.fetchData()
.subscribe((data) => {
this.data = [];
this.data = data;
this.heads = Object.keys(data[0]);
var len = this.heads.length;
console.log(this.heads);
},
err => console.log(err),
() => console.log('Completed'));
}
答案 1 :(得分:2)
你有一个Extra BackTick导致整个代码成为一个字符串。只需删除它。复制粘贴以下代码: -
import {Component} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import {Http} from 'angular2/http';
import {SpsheetService} from './spsheet.service';
import 'rxjs/Rx';
@Component({
selector: 'my-spsheet',
template: `
<button id="fetch" (click)="reloadData()">Reload Data</button>
<table class="table">
<thead>
<tr>
<th *ngFor="#head of heads">
{{head | async}}
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="#dat of data">
<td *ngFor="#head of heads" contenteditable="true">
{{dat.head | async}}
</td>
</tr>
</tbody>
</table>
`,
],
providers: [SpsheetService]
})
export class SpsheetComponent {
data:any[];
heads:string[];
otherdata:string[];
constructor(private _http:Http,private _spservice:SpsheetService){}
reloadData(){
this._spservice.fetchData()
.subscribe(function(data)
{
var me =this;
me.data =[];
me.data = data;
me.heads = Object.keys(data[0]);
var len = me.heads.length;
console.log(me.heads);
},
err => console.log(err),
() => console.log('Completed'));
}
}
答案 2 :(得分:1)
我已经解决过这个问题,这实际上是一个问题,而这个&#39;订户的实例。
实际正确的代码是:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
vectors=np.array( [ [0,0,1,1,-2,0], [0,0,2,1,1,0],[0,0,3,2,1,0],[0,0,4,0.5,0.7,0]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for vector in vectors:
v = np.array([vector[3],vector[4],vector[5]])
vlength=np.linalg.norm(v)
ax.quiver(vector[0],vector[1],vector[2],vector[3],vector[4],vector[5],
pivot='tail',length=vlength,arrow_length_ratio=0.3/vlength)
ax.set_xlim([-4,4])
ax.set_ylim([-4,4])
ax.set_zlim([0,4])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()