重构代码:优化json返回值,提高传输效率
This commit is contained in:
parent
39fea964b5
commit
c51c659685
|
@ -1,5 +1,4 @@
|
||||||
using Bootstrap.DataAccess;
|
using Bootstrap.DataAccess;
|
||||||
using Bootstrap.Security;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -15,7 +14,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IEnumerable<BootstrapDict> Get()
|
public IEnumerable<string> Get()
|
||||||
{
|
{
|
||||||
return DictHelper.RetrieveCategories();
|
return DictHelper.RetrieveCategories();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,8 @@
|
||||||
$.bc({
|
$.bc({
|
||||||
url: "api/Category",
|
url: "api/Category",
|
||||||
callback: function (result) {
|
callback: function (result) {
|
||||||
var data = result.map(function (ele, index) { return ele.Category; });
|
|
||||||
$('#txt_dict_cate').typeahead({
|
$('#txt_dict_cate').typeahead({
|
||||||
source: data,
|
source: result
|
||||||
autoSelect: true
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -95,18 +95,18 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获取字典分类名称
|
/// 获取字典分类名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<BootstrapDict> RetrieveCategories()
|
public static IEnumerable<string> RetrieveCategories()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
||||||
{
|
{
|
||||||
var ret = new List<BootstrapDict>();
|
var ret = new List<string>();
|
||||||
string sql = "select distinct Category from Dicts";
|
string sql = "select distinct Category from Dicts";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
|
ret.Add((string)reader[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue