【问题标题】:`Linq` Query contains group join and requires looping throughout Json Array`Linq` 查询包含组加入并需要在整个 Json 数组中循环
【发布时间】:2015-10-10 14:18:40
【问题描述】:

您好,我有以下 linq 查询:

         var resulta = from a in db.users
         join b in db.userlogin on a.ID equals b.ID into UserGroup
         select new {a.age , a.location , logindetail = UserGroup}

         var resultb = contains other linq data which is irrelvant for this question

          var resultc = new { users = resulta , business = resultb }

这都返回在 MVC 视图中输出的 json 数据。剃刀 HTML 包含以下内容:

//this loops throughout the user data and find their indexes along with  values
$.each(data.users) , function (index , item) {

//This variable contains an empty string which will be appended to with the following inner loop
var string = '';

// this is a inner loop to search throughout UserGroup
$.each(item.logindetail) , function (index , itema) {
string += <span> + itema.usergroup + itema.email + itema.password + </span>;

在我可以将以下内容附加到 div 容器之前,上面的循环似乎不起作用,因为 itema 没有被识别,因此无法遍历 item.logindetail 中的各个项目。

谢谢

【问题讨论】:

    标签: javascript jquery json linq model-view-controller


    【解决方案1】:

    您的内部循环对象名称应该是 item.logindetail 而不是您使用 item.UserGroup

    【讨论】:

    • 嗨,即使我使用 item.logindetail,它仍然无法正常工作?谢谢
    • 对不起,我的意思是说这有效,但函数中的 itema 仍然没有返回任何内容?
    【解决方案2】:

    改变你的内循环。

    新代码:

    $.each(item.logindetail) , function (index , itema) {
    string += <span> itema.email + itema.password + </span>; 
    

    【讨论】:

    • 这可行,但是函数中的 itema 仍然没有返回任何内容?
    • 尝试 console.log(itema); 检查你有什么。如果您没有收到电子邮件和密码,请检查您的回复。
    • callback is undefined ,这似乎很奇怪,因为该项目应该存在?谢谢
    • 请发表您对 resulta 的回复。
    猜你喜欢
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多