我有一个包含组成组件的小部件:
<div data-bind="visible:searchfieldvisibilityconfig.isVisible('SearchScreening_Branch')">
@Html.CreateTypeaheadInput("widget.branch", "searchCriteria.Branch", GetValueList("ScreeningBranch"))
</div>
CreateTypeaheadInput 返回以下内容:
public static HtmlString CreateTypeaheadInput(this HtmlHelper html, string i18nKey, string valueBinding,
ValueList valueList, params string[] additionalDataBindings)
{
var options = string.Join("",
valueList.Select(
v =>
$@"<option {GetSelectedState(v)} value=""{v.Value}""{GetCustomDataAttributes(v)} {GetAttributes(v)}>{
HttpUtility.HtmlAttributeEncode(v.ValueText)
}</option>"));
const string template = @"<section data-bind=""validationElement: {1}"" >
<label class=""select"">
<select class=""input-xs {4}"" data-bind=""{3}"">{2}</select>
<b class=""tooltip tooltip-top-right"">
<i class=""fa txt-color-teal""></i>
<span data-i18n=""{0}""></span>
</b>
</label>
<div class=""note note-error"" style=""display: none;"" data-bind=""validationMessage: {1}""></div>
</section>";
var specificCssClass = GetSpecificCssClassForHtmlTag("select", valueBinding);
var bindingString = $"typeahead: {{value: {valueBinding}}}, ";
if (additionalDataBindings != null)
{
var additionalBindingString = string.Join(",", additionalDataBindings);
bindingString = string.Join(",", bindingString, additionalBindingString);
}
return new HtmlString(string.Format(template, i18nKey, valueBinding, options, bindingString, specificCssClass));
}
实际上,我目前在UI上有一个允许输入的框。如果我键入的内容与 valueList 中的值之一匹配,那么我一开始输入文字,就可以选择它。不幸的是,这不允许我放置自由文本。您是否有可能的解决方案?预先感谢!