ng-admin 无法识别自定义字段视图
ng-admin does not recognize custom field view
我正在使用 ng-admin。
根据doc,我创建了一个自定义字段。
ng-admin 识别 FooFiledType 但它不呈现 FoofieldView 并使用原始的 FieldView !
配置模块:
angular.module('admin', ['ng-admin']);
import FooField from './FooFieldType';
angular.module('admin')
.config(['NgAdminConfigurationProvider', function (nga) {
nga.registerFieldType('foo', FooField);
}])
.config(['FieldViewConfigurationProvider', function (fvp) {
fvp.registerFieldView('foo', require('./FooFieldView'));
}])
;
angular.module('admin').config(['NgAdminConfigurationProvider', function (nga) {
var bar = nga.entity('bar');
bar.creationView().fields([nga.field('foo','foo')]);
});
FooField.js :
import Field from 'admin-config/lib/Field/Field';
class FooField extends Field {
constructor(name) {
super(name);
}
}
export default FooField;
FooFieldView.js :
export default {
// displayed in listView and showView
getReadWidget : () => '<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-number-column>',
// displayed in listView and showView when isDetailLink is true
getLinkWidget : () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>',
// displayed in the filter form in the listView
getFilterWidget : () => '<ma-input-field type="number" field="::field" value="values[field.name()]"></ma-input-field>',
// displayed in editionView and creationView
getWriteWidget : () => '<h1>testFoo</h1><ma-input-field type="number" field="::field" value="entry.values[field.name()]"></ma-input-field>'
};
Doc 似乎不完整...但我已将其缩小到字段中缺少的 'this._type' 设置。您需要更改 FooField.js 如下:
....
class FooField extends Field {
constructor(name) {
super(name);
//THIS IS THE IMPORTANT PART:
this._type = 'foo';
//DOC DOESN'T SPEAK ABOUT
}
}
....
当您在 FooField class 中定义 _type 时,将调用并呈现根据类型的视图。否则,由于我们继承自 'Field',因此呈现了 String 视图,但似乎没有任何效果...
Doc 确实需要更新 :)
我正在使用 ng-admin。
根据doc,我创建了一个自定义字段。
ng-admin 识别 FooFiledType 但它不呈现 FoofieldView 并使用原始的 FieldView !
配置模块:
angular.module('admin', ['ng-admin']);
import FooField from './FooFieldType';
angular.module('admin')
.config(['NgAdminConfigurationProvider', function (nga) {
nga.registerFieldType('foo', FooField);
}])
.config(['FieldViewConfigurationProvider', function (fvp) {
fvp.registerFieldView('foo', require('./FooFieldView'));
}])
;
angular.module('admin').config(['NgAdminConfigurationProvider', function (nga) {
var bar = nga.entity('bar');
bar.creationView().fields([nga.field('foo','foo')]);
});
FooField.js :
import Field from 'admin-config/lib/Field/Field';
class FooField extends Field {
constructor(name) {
super(name);
}
}
export default FooField;
FooFieldView.js :
export default {
// displayed in listView and showView
getReadWidget : () => '<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-number-column>',
// displayed in listView and showView when isDetailLink is true
getLinkWidget : () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>',
// displayed in the filter form in the listView
getFilterWidget : () => '<ma-input-field type="number" field="::field" value="values[field.name()]"></ma-input-field>',
// displayed in editionView and creationView
getWriteWidget : () => '<h1>testFoo</h1><ma-input-field type="number" field="::field" value="entry.values[field.name()]"></ma-input-field>'
};
Doc 似乎不完整...但我已将其缩小到字段中缺少的 'this._type' 设置。您需要更改 FooField.js 如下:
....
class FooField extends Field {
constructor(name) {
super(name);
//THIS IS THE IMPORTANT PART:
this._type = 'foo';
//DOC DOESN'T SPEAK ABOUT
}
}
....
当您在 FooField class 中定义 _type 时,将调用并呈现根据类型的视图。否则,由于我们继承自 'Field',因此呈现了 String 视图,但似乎没有任何效果...
Doc 确实需要更新 :)