数据绑定与json文件中的智能表

时间:2017-09-26 04:39:33

标签: javascript angularjs json

我想将json文件绑定到智能表。如何使用循环函数进行迭代..请帮忙 它只显示了智能表的设计。 没有绑定json的数据

这是json文件



[
	{
        "year": 2013, 
        "id": "", 
        "doctor": "Dr. Smith", 
        "illness": "Flu", 
        "apptdate": "3/12/2013",
		"details":"Patient had flu for 5 days. No medicines prescribed"
	}
]




我曾经使用

检索数据



@Injectable()
export class SmartTablesService {
  constructor(private http: Http) {
    
        }
        smartTableData = [];
loadData() {
  console.log('loadData');
   this.http.get('http://192.168.0.100:8000/medical')

.subscribe((data) => {
          setTimeout(() => {
              var contactData = [];
              $.each(data.json(), function (key, value) {
                  var tempData = value.source;
                  contactData.push(tempData);
              });
              this.smartTableData = contactData;
          }, 1000);
      });
}
getData(): Promise<any> {
  console.log("Promise");
  this.loadData();
  return new Promise((resolve, reject) => {
      setTimeout(() => {
          console.log(this.smartTableData);
          resolve(this.smartTableData);
      }, 3000);
  });
}
}

    constructor(private http: Http) { }
       getComments() {
        
       return this.http.get('http://192.168.0.100:8000/article' )
          .map((res: Response) => res.json())
          .catch((error:any) => Observable.throw(error));
       }
}*/
&#13;
&#13;
&#13;

这是组成部分

&#13;
&#13;
@Component({
  selector: 'new',
  template: '<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>'
})
export class NewComponent {
    query: string = '';
    
      settings = {
        noDataMessage: 'Loading...',
       columns: {
        year: {
            title: 'YEAR',
            type: 'string'
          },
          id: {
            title: 'ID',
            type: 'string'
          },
          doctor: {
            title: 'DOCTOR',
            type: 'string'
          },
          illness: {
            title: 'ILLNESS',
            type: 'string'
          },
          apptdate: {
            title: 'APPTDATE',
            type: 'string'
          },
          details: {
            title: 'DETAILS',
            type: 'string'
          }
      }
      };
    
// data

source: LocalDataSource = new LocalDataSource();
constructor(protected service: SmartTablesService){
  this.service.getData().then((data) => {
    this.source.load(data);
  });
}  
}
&#13;
&#13;
&#13;

请任何人都知道如何绑定它..help

1 个答案:

答案 0 :(得分:0)

只需将服务页面中的订阅部分更改为

即可

&#13;
&#13;
syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /root/.local/share/Trash/files/keystone_laravel.2/laravel/artisan on line 3
&#13;
&#13;
&#13;

所以.subscriber看起来像

&#13;
&#13;
var tempData = value;
&#13;
&#13;
&#13;

它有效..!