Appearance
支持值变更命令
虽然单元格插件可以通过声明命令属性也可以实现值变更命令的效果。但是对于表单类单元格来说,推荐使用更简便的方法,即实现 ICommandCellType接口来实现值变更命令
C#示例代码如下。
csharp
public class MyPluginCellType : CellType, ICommandCellType
{
[DisplayName("值变更命令")]
public List<Command> CommandList { get; set; }
public CommandExcuteKind CommandExcuteKind => CommandExcuteKind.OnValueChanged;
}实现了ICommandCellType,并且CommandExcuteKind 返回OnValueChanged,活字格会在单元格值变更时主动调用用户设置的命令,JavaScript不需要为此命令写任何额外的代码。只需支持单元格值即可。
javascript
class MyPluginCellType extends Forguncy.Plugin.CellTypeBase {
createContent() {
this.input = $("<input style='width:100%;height:100%'>");
this.input.change(() => {
this.commitValue();
})
return this.input;
}
setValueToElement(_, value) {
this.input.val(value?.toString());
}
getValueFromElement() {
return this.input.val();
}
}
Forguncy.Plugin.CellTypeHelper.registerCellType("MyPlugin.MyPluginCellType, MyPlugin", MyPluginCellType);命令属性 Vs ICommandCellType实现值变更命令
- 使用ICommandCellType实现值变更命令无需额外的JavaScript代码
- 使用ICommandCellType实现值变更命令原生支持在条件命令中获取“值变更原因”上下文变量
更新: 2022-11-30 22:20:23
原文: https://www.yuque.com/robert-bh51n/ea8l6c/ruw7wlkx7gf0tkxh