问题是我正在尝试选择带有$(“a”)的元素,它只会影响文档中的少数标记,我的代码
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'http://localhost/queryProjects',
success: function(data) {
var el = $('<div></div>');
el.html(data);
var ProjectsObject = $("b:contains('projectName')", el).parent().next();
var ProjectsArray = $.makeArray(ProjectsObject);
var DescriptionsObject = $("b:contains('description')", el).parent().next();
var DescriptionsArray = $.makeArray(DescriptionsObject);
for (var i = 0; i < ProjectsArray.length; i++) {
$("tbody:last-child").append('<tr><td>' + (i + 1) + '</td><td><a id="link" href="#">' + ProjectsArray[i].textContent + '</a></td>' + '<td>' + DescriptionsArray[i].textContent + '</td><td style="margin-right=40px;"><a href="#">Run</a></td></tr>');
}
}
});
$("a#link").click(function() {
$("table").hide();
});
});
我尝试使用ID而不使用$(“a”)和$(“a#link”)。
AJAX是无关紧要的,只是让你看到我如何将我的信息注入文档。
谢谢!
答案 0 :(得分:0)
尝试在代码内部移动成功。就在for循环之后。
public JsonResult PODetailsList(int id)
{
List<PODetailsFull> Products;
Products =
(from d in db.PODetails
join p in db.Products on d.ProductID equals p.ProductID
where d.POID == id
select new PODetailsFull
{
PODetailID = d.PODetailID,
//QtyRegion = new List<string>() { Region.Region + " " + POAllocation.Allocate != null ? POAllocation.Allocate.ToString() : "" },
Sku = p.Sku,
Cntnr20 = p.Cntnr20 ?? 0,
Cntnr40 = p.Cntnr40 ?? 0,
Cntnr40HQ = p.Cntnr40HQ ?? 0,
}).ToList();
foreach (var product in Products)
{
var result = (from POAllocation in db.POAllocations.Where(p => p.PODetailID == product.PODetailID)
join regions in db.Regions on POAllocation.RegionID equals regions.RegionID
select regions.Region + " " + POAllocation.Allocate ?? ""
).ToList();
product.QtyRegion = result;
}
return Json(new { data = Products }, JsonRequestBehavior.AllowGet);
}