如何在 SAPUI5 输入字段中添加浏览器缓存自动完成功能?

问题描述:

如何在 SAPUI5 输入字段中添加浏览器缓存自动完成?

How to add browser cache autocomplete in SAPUI5 Input field?

我有一个带有输入字段的 SAPUI5 表单.我希望这些输入字段像任何其他网站一样显示浏览器历史记录中的自动完成.有什么想法吗?

I have a SAPUI5 form with input fields. I want these input fields to display autocomplete from browser history like any other website. Any idea?

您的问题有点含糊,但我猜您想启用浏览器级别的表单字段自动完成功能.类似于这个问题:使文本输入字段记住以前输入的数据一>.

Your question is a little vague, but I guess that you want to enable browser-level form field autocomplete. Something like in this question: Make text input fields remember previously entered data.

主要问题是浏览器会在这些条件下保存有关字段值的信息:

The main catch is that the browser saves information regarding to field values under these conditions:

  • 输入字段有名称(您可以通过 UI5 sap.m.Input 控件的名称"属性设置输入字段的名称).
  • 提交包含表单.

通常,您不会在 UI5 中提交表单,因为这是一种非 AJAX 传递数据的方式.你可以看看这个问题:触发自动完成而不提交表单求解决办法解决这个问题.

Generally, you don't submit forms in UI5, because this is a non-AJAX way of passing data. You can look at this question: Trigger autocomplete without submitting a form for a solution to this problem.

或者,您可以自己存储值,例如localStorage 并使用它们来填充 sap.m.Input 的建议项聚合.

Alternatively, you can store the values by yourself in e.g. the localStorage and use them to fill up the sap.m.Input's suggestionItems aggregation.