web端也能使用linq查询,百度一下linq.js.
下面是别人的链接
最新版
老版本
下面是记录自己项目中的具体使用
1. 老版本 (可以舍弃掉 使用最新的)
//引入老版本的js
<script src="../Script/libs/JSLINQ.js"></script>
///根据组织ID查询出部门
var selectDe = JSLINQ(Depeart).Where(function (item) {
return item.ParentID == Organiza[i].OrganizationID;
}).OrderBy(function (item) {
return item.Orders;
}).Select(function (item) {
return item;
});
- 新版本
<script src="../Script/libs/linq.min.js"></script>
//查询是否存在根组织(总公司)
var count = Enumerable.From(data).Select("p=>p.OrganizationID=='" + FirstOrang.OrganizationID + "'").Count();
console.info(count);
if (count<=0) {
//不存在根组织 加入
html += "<div class='list-group'>";
html += " <a href='#' class='list-group-item ' style='background-color: #f5f5f5;'>";
html += " <h4 class='list-group-item-heading'>" + FirstOrang.OrganizationName + "</h4></a>";
html += "</div>";
}
//将数据根据组织分组
var orangid = "";
var group1 = Enumerable.From(data).Distinct("p=>p.OrganizationName").GroupBy("p=>p.OrganizationName").ToArray();
console.info(group1);
//遍历组织 两次循环才能遍历到组织
group1.forEach(function (v,i) {
v.source.forEach(function (sv, si) {
html += "<div class='list-group'>";
html += " <a href='#' class='list-group-item ' style='background-color: #f5f5f5;'>";
html += " <h4 class='list-group-item-heading'>" + sv.OrganizationName + "</h4></a>";
orangid = sv.OrganizationID;
//将数据根据部门和组织分组
var Degroup = Enumerable.From(data).Where("p=>p.OrganizationID=='" + orangid + "'").OrderBy("p=>p.Orders").GroupBy("p=>p.DepartmentName").ToArray();
console.info(Degroup);
//遍历部门
Degroup.forEach(function (dv, di) {
var depeartid = "";
dv.source.forEach(function (dv1,di1) {
if (depeartid == dv1.DepartmentID) {
depeartid = dv1.DepartmentID;
}
else {
console.info(dv1.DepartmentName);
depeartid = dv1.DepartmentID;
var count = dv.source.length;
//加入部门开始
html += "<div class='dlist'>";
html += " <a href='javascript:void(0)' class='list-group-item depeart' onclick='ShowMedia(" + dv1.DID + ")'>";
html += "<span class='badge' style='background-color:#d9534f'>" + count + "</span>";
if (dv1.DID == '19' || dv1.DID == '17') {
html += " <h4 class='list-group-item-heading' style='font-size: 12px'>" + dv1.DepartmentName + " </h4>";
} else {
html += " <h4 class='list-group-item-heading' >" + dv1.DepartmentName + " </h4>";
}
//加入部门结束
//遍历人员开始
html += "<div class='showsuer de" + dv1.DID + "'>";
dv.source.forEach(function (uv,ui) {
var img = uv.UserFaceImage == null || uv.UserFaceImage == "" ? "/Images/headpic.png" : uv.UserFaceImage;
html += ' <div class="media" onclick="UserDetal(' + uv.UserID + ')" >';
html += ' <a class="media-left" href="#">';
html += ' <img class="media-object img-circle" src="' + img + '" alt="媒体对象">';
html += ' </a>';
html += ' <div class="media-body">';
html += '<dl><dt><strong class="title">' + uv.TrueName + '</strong><span class="tel">' + uv.MobilePhone + '</span><span class="oright">人气 <code>' + uv.ClickCount + '</code></span></dt><dt> <code><code class="star-1"></code><code class="star-1"></code><code class="star-1"></code><code class="star-1"></code><code class="star-1"></code><cite>5.0</cite>分<span class="oright" style="color:#888;">成交 <code>0</code></span></code></dt><dt class="ddt"><code><span style=" color:#888;">点评 <code>0</code><span><span style="margin-left:10px; color:#888;">好评 <code>0</code></span><span style="margin-left:10px;color:#888;">差评 <code>0</code></span></span></span></code></dt><dd style="color: rgb(51, 51, 51);"><code><i class="placeIcon"></i><span id="1distanceSupp4">角色:' + uv.RoleName + '</span><span class="oright"> </span></code></dd></dl>';
html += ' </div>';
html += '</div>';
});
//遍历人员结束
html += "</div>";
}
});
});
html += "</div>";
});
});