使用 ember-light-table 时遇到问题
Facing issue in using ember-light-table
我正在学习 ember js,我遇到了 ember-light-table 作为 data-tables 的替代品。
我只想将一些静态数据显示到 table。因此,我没有创建 mixin 和组件,而是将代码直接写入路由文件。 (不确定事情是否会以这种方式工作)。
下面是我的路由文件
import Route from '@ember/routing/route';
import Table from 'ember-light-table';
import { computed } from '@ember/object';
export default Route.extend({
table : null,
columns: computed(function() {
return [{
label: 'Email',
valuePath: 'email'
}, {
label: 'Name',
valuePath: 'name'
}];
}),
rows: computed(function() {
return [{
"email":"abc@gmail.email",
"name":"Abc"
}, {
"email":"xyz@gmail.email",
"name":"Xyz"
}];
}),
init(){
this._super(...arguments);
let table = new Table(this.get('columns'),this.get('rows'));
console.log("table = ",table);
this.set('table', table);
}
});
模板文件
{{#light-table table height='65vh' as |t|}}
{{t.head fixed=true }}
{{#t.body canSelect=false as |body| }}
{{/t.body}}
{{/light-table}}
我在控制台中遇到以下错误:
Error: Assertion Failed: [ember-light-table] table must be an instance of Table
我也看过文档和其他博客的代码,代码看起来是一样的,但不确定我是否遗漏了什么。
提前致谢。
不要在路由器中执行此操作,而是创建一个组件。
现在您的路由器也有问题,因为路由器中没有 init 挂钩,但您想在组件中使用 init 挂钩。
将所有路由器代码放在组件中,当然除了导入路由器和扩展路由器以及组件模板中的模板。在您现在使用的模板中,调用您的组件,这应该可以解决问题
我正在学习 ember js,我遇到了 ember-light-table 作为 data-tables 的替代品。
我只想将一些静态数据显示到 table。因此,我没有创建 mixin 和组件,而是将代码直接写入路由文件。 (不确定事情是否会以这种方式工作)。
下面是我的路由文件
import Route from '@ember/routing/route';
import Table from 'ember-light-table';
import { computed } from '@ember/object';
export default Route.extend({
table : null,
columns: computed(function() {
return [{
label: 'Email',
valuePath: 'email'
}, {
label: 'Name',
valuePath: 'name'
}];
}),
rows: computed(function() {
return [{
"email":"abc@gmail.email",
"name":"Abc"
}, {
"email":"xyz@gmail.email",
"name":"Xyz"
}];
}),
init(){
this._super(...arguments);
let table = new Table(this.get('columns'),this.get('rows'));
console.log("table = ",table);
this.set('table', table);
}
});
模板文件
{{#light-table table height='65vh' as |t|}}
{{t.head fixed=true }}
{{#t.body canSelect=false as |body| }}
{{/t.body}}
{{/light-table}}
我在控制台中遇到以下错误:
Error: Assertion Failed: [ember-light-table] table must be an instance of Table
我也看过文档和其他博客的代码,代码看起来是一样的,但不确定我是否遗漏了什么。
提前致谢。
不要在路由器中执行此操作,而是创建一个组件。
现在您的路由器也有问题,因为路由器中没有 init 挂钩,但您想在组件中使用 init 挂钩。
将所有路由器代码放在组件中,当然除了导入路由器和扩展路由器以及组件模板中的模板。在您现在使用的模板中,调用您的组件,这应该可以解决问题