重构代码:优化json返回值,提高传输效率
This commit is contained in:
parent
39fea964b5
commit
c51c659685
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue