我有一个支持建议的输入
要搜索数字,我必须先输入前导零。我该如何绕过?
代码:
<Label text="Assign to" labelFor="pmRespPers"/>
<Input id="pmRespPers" type="Text" placeholder="Enter Person respons." showSuggestion="true"
suggestionRows="{EAMMALFUNCTION>/I_PMContactCardEmployee}">
<layoutData>
<layout:GridData span="L7 M7 S12"/>
</layoutData>
<suggestionColumns>
<Column hAlign="Begin" popinDisplay="Inline" demandPopin="true">
<Label text="Number"/>
</Column>
<Column hAlign="Center" popinDisplay="Inline" demandPopin="true" minScreenWidth="Tablet">
<Label text="Fullname"/>
</Column>
</suggestionColumns>
<suggestionRows>
<ColumnListItem>
<cells>
<Label text="{EAMMALFUNCTION>PersonnelNumber}"/>
<Label text="{EAMMALFUNCTION>EmployeeFullName}"/>
</cells>
</ColumnListItem>
</suggestionRows>
</Input>
答案 0 :(得分:0)
在输入中使用"suggest" event。每次用户在“输入”中输入时都会触发。
作为事件对象的参数,您将获得“值”。 因此,在事件处理函数中,可以根据需要修改值(添加零),并使用修改后的值过滤建议列表。
您还需要禁用默认过滤以避免冲突。以下是代码段:https://jsbin.com/welimufado/edit?html,output
<Input id="productInput" type="Text" placeholder="Enter Product ..."
showSuggestion="true" filterSuggests="false" suggestionItems="{/products}" suggest="onSuggest">
<suggestionItems>
<core:Item text="{Name}" />
</suggestionItems>
</Input>
事件处理程序
onSuggest: function(oEvent){
var sValue = oEvent.getParameters().suggestValue;
var sModifiedValue = "0000" + sValue;
var oFilter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.StartsWith, sModifiedValue);
oEvent.getSource().getBinding("suggestionItems").filter(oFilter);
}
具有表格建议的代码段: https://jsbin.com/wovovofece/edit?html,output
答案 1 :(得分:0)
我有解决方法:
onSuggest: function(oEvent) {
const oSuggestionRows = oEvent.getSource().getSuggestionRows();
oSuggestionRows.map(a => {
const oFirstLabel = a.getCells()[0];
const iPersonnel = oFirstLabel.getText();
const iPlConverted = parseInt(iPersonnel, 10);
oFirstLabel.setText(iPlConverted);
return oFirstLabel;
});