减少TraceItem数据量较大时的性能浪费
智能大石头 authored at 2024-10-22 08:41:14
2.05 KiB
Stardust
@model SelectAppModel
@using NewLife;
@using NewLife.Web;
@using XCode;
@using System.Linq;
@using Stardust.Data;
@using Stardust.Web.Models;
@{
    var id = Model.Id;
    var page = ViewBag.Page as Pager;

    if (id.IsNullOrEmpty()) { id = "appId"; }
    var appId = Model.AppId;
    if (appId <= 0) appId = page[id].ToInt();
    var showValue = App.FindById(appId)?.Name;
}

<div class="form-group" style="position:relative">
    <div class="col-lg-12">
        <div class="input-group">
            <input type="hidden" name="@id" id="@id" value="@appId" />
            <input type="text" class="form-control" id="@(id)_select" placeholder="搜索应用" value="@showValue">
            <div class="input-group-btn">
                <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
            </div>
        </div>
    </div>
</div>

<script src="~/Content/bootstrap-suggest.js"></script>
<script type="text/javascript">
    $(function () {
        $("#@(id)_select").bsSuggest({
            url: "/Registry/App/AppSearch?category=@Model.Category&key=",
            getDataMethod:"url",
            effectiveFieldsAlias: { id: "编号", name: "名称", displayName: "显示名", category: "类别" },
            ignorecase: true,
            showHeader: true,
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时,延迟到有输入/获取到焦点时才请求数据
            hideOnSelect: true,
            idField: "id",
            showBtn: false,
            keyField: "name",
            clearable: true,
            searchingTip: '搜索中...',
            allowNoKeyword: true,
            delay: 500,
            emptyTip: '无数据',
            containerValueId: '@id',
            fnProcessData: function (result) {
                dt = {};
                dt.value = result.data;
                return dt;
            }
        }).on('onSetSelectValue', function (e, keyword, data) {
            $('#@id').val(keyword.id);
        }).on('onUnsetSelectValue', function () {
            $('#@id').val('');
        });
    });
</script>