2015-10-10 23 views
0

嗨需要循環,我有以下LINQ查詢:`Linq`查詢包含組的加入和整個JSON數組

  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容器,上面的循環似乎沒有工作,因爲意達不被認可,因此可以通過單個項目沒有環item.logindetail。

謝謝

回答

0

你內環對象名稱應改爲item.logindetail你必須使用item.UserGroup

+0

嗨仍無法當我使用item.logindetail工作什?謝謝 –

+0

對不起,我的意思是說這個工程,但函數內的itema仍然沒有返回? –

0

更改你的內部循環。

新代碼:

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

這工作,但功能內的itema仍然沒有返回? –

+0

嘗試** console.log(itema); **來檢查你所得到的結果。如果您沒有收到電子郵件和密碼,請檢查您的回覆。 –

+0

回調是未定義的,這似乎很奇怪,因爲該項目應該存在?謝謝 –