Node.js 数据表编辑器 - 根据特定值筛选 select 选项
Node.js datatables editor - Filter select option depending on a certain value
我正在使用 node.js 数据table 编辑器库。当尝试根据 table 'portfolios_isin' 中的特定字段 (user_id) 过滤 select 选项时,如下所示:
node.js
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(() => {
//this.where('user_id', '=', '1')
this.where('portfolios_isin.user_id', '=', '1')
})
),
new Field( 'securities.issuer_name' )
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' );
我收到这个错误:
TypeError: this.where is not a function
at Builder.Editor.fields.Field.options.Options.table.value.label.where (/home/project/controllers/myproject.js:359:30)
at Formatter.compileCallback (/home/project/node_modules/knex/lib/formatter.js:161:14)
at Formatter.rawOrFn (/home/project/node_modules/knex/lib/formatter.js:104:36)
at QueryCompiler_MySQL.whereWrapped (/home/project/node_modules/knex/lib/query/compiler.js:531:30)
at QueryCompiler_MySQL.where (/home/project/node_modules/knex/lib/query/compiler.js:314:32)
at /home/project/node_modules/knex/lib/query/compiler.js:147:30
at Array.map (<anonymous>)
at QueryCompiler_MySQL.select (/home/project/node_modules/knex/lib/query/compiler.js:146:33)
at QueryCompiler_MySQL.toSQL (/home/project/node_modules/knex/lib/query/compiler.js:108:27)
at Builder.toSQL (/home/project/node_modules/knex/lib/query/builder.js:115:44)
at /home/project/node_modules/knex/lib/runner.js:56:32
at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
at /home/project/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/project/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/project/node_modules/bluebird/js/release/promise.js:569:18)
根据文档 https://editor.datatables.net/manual/nodejs/joins 这是实现的方法。我有一个类似的项目,我在其中使用 php datatable 编辑器库(并且一切正常)...在那里我可以像这样过滤选项:
php:
Editor::inst( $db, 'portfolios_isin_mm' )
->fields(
Field::inst( 'portfolios_isin_mm.account_id' ),
Field::inst( 'portfolios_isin_mm.user_id' ),
Field::inst( 'portfolios_isin_mm.uid_foreign' )
->options( 'portfolios_isin', 'id', 'portfolio_name', function ($q) {
$q->where( 'portfolios_isin.user_id', '1', '=' );
}),
Field::inst( 'securities.issuer_name' )
)
->leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
如何在 node.js 的编辑器中过滤选项值?
this.where
超出了函数 where
存在的范围,因为您正在使用将 this
绑定到 outer/parent 范围的箭头函数。
试试这个:
.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),
我正在使用 node.js 数据table 编辑器库。当尝试根据 table 'portfolios_isin' 中的特定字段 (user_id) 过滤 select 选项时,如下所示:
node.js
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(() => {
//this.where('user_id', '=', '1')
this.where('portfolios_isin.user_id', '=', '1')
})
),
new Field( 'securities.issuer_name' )
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' );
我收到这个错误:
TypeError: this.where is not a function
at Builder.Editor.fields.Field.options.Options.table.value.label.where (/home/project/controllers/myproject.js:359:30)
at Formatter.compileCallback (/home/project/node_modules/knex/lib/formatter.js:161:14)
at Formatter.rawOrFn (/home/project/node_modules/knex/lib/formatter.js:104:36)
at QueryCompiler_MySQL.whereWrapped (/home/project/node_modules/knex/lib/query/compiler.js:531:30)
at QueryCompiler_MySQL.where (/home/project/node_modules/knex/lib/query/compiler.js:314:32)
at /home/project/node_modules/knex/lib/query/compiler.js:147:30
at Array.map (<anonymous>)
at QueryCompiler_MySQL.select (/home/project/node_modules/knex/lib/query/compiler.js:146:33)
at QueryCompiler_MySQL.toSQL (/home/project/node_modules/knex/lib/query/compiler.js:108:27)
at Builder.toSQL (/home/project/node_modules/knex/lib/query/builder.js:115:44)
at /home/project/node_modules/knex/lib/runner.js:56:32
at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
at /home/project/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/project/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/project/node_modules/bluebird/js/release/promise.js:569:18)
根据文档 https://editor.datatables.net/manual/nodejs/joins 这是实现的方法。我有一个类似的项目,我在其中使用 php datatable 编辑器库(并且一切正常)...在那里我可以像这样过滤选项:
php:
Editor::inst( $db, 'portfolios_isin_mm' )
->fields(
Field::inst( 'portfolios_isin_mm.account_id' ),
Field::inst( 'portfolios_isin_mm.user_id' ),
Field::inst( 'portfolios_isin_mm.uid_foreign' )
->options( 'portfolios_isin', 'id', 'portfolio_name', function ($q) {
$q->where( 'portfolios_isin.user_id', '1', '=' );
}),
Field::inst( 'securities.issuer_name' )
)
->leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
如何在 node.js 的编辑器中过滤选项值?
this.where
超出了函数 where
存在的范围,因为您正在使用将 this
绑定到 outer/parent 范围的箭头函数。
试试这个:
.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),