如何在 ui5 中重置 customData 值?

How to reset a customData value in ui5?

我想通过单击按钮更改自定义数据值,我可以使用 oEvent.getSource().data("key") 获取该值,但如何重置它?

oEvent.getSource().data().key =1

以上代码无效

删除自定义数据

oEvent.getSource().data("key", null); // or
oEvent.getSource().removeCustomData(sCustomDataId);

或全部删除:

oEvent.getSource().data(null); // or
oEvent.getSource().destroyCustomData();

添加或修改自定义数据

oEvent.getSource().data("key", data); // or
oEvent.getSource().addCustomData(new CustomData({ // required from "sap/ui/core/CustomData"
  key: "key",
  value: data
}));

here

顺便说一句:不推荐像使用 oSource<strong>.data().key</strong> 那样访问属性。您应该始终使用 getters/setters.