重构代码:优化json返回值,提高传输效率

This commit is contained in:
Argo-MacBookPro 2018-09-09 18:52:10 +08:00
parent 39fea964b5
commit c51c659685
3 changed files with 5 additions and 8 deletions

View File

@ -1,5 +1,4 @@
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
@ -15,7 +14,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public IEnumerable<BootstrapDict> Get()
public IEnumerable<string> Get()
{
return DictHelper.RetrieveCategories();
}

View File

@ -26,10 +26,8 @@
$.bc({
url: "api/Category",
callback: function (result) {
var data = result.map(function (ele, index) { return ele.Category; });
$('#txt_dict_cate').typeahead({
source: data,
autoSelect: true
source: result
});
}
});

View File

@ -95,18 +95,18 @@ namespace Bootstrap.DataAccess
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveCategories()
public static IEnumerable<string> RetrieveCategories()
{
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
{
var ret = new List<BootstrapDict>();
var ret = new List<string>();
string sql = "select distinct Category from Dicts";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
ret.Add((string)reader[0]);
}
}
return ret;