Reputation: 195
I want to get the properties through .each
function?
public class UserDto
{
public List<UserNode> UserList { get; set; }
}
public class UserNode
{
public UserNode()
{
UserViews = new List<string>();
}
public Guid Id { get; set; }
public IList<string> UserViews { get; set; }
}
how i can extract values through .each function? i wanna to show the id and userviews?
success: function (userDetails) {
$.each(userDetails, function() {
$.each(this, function (key, value) {
alert(value);
});
});
},
any way to get this?
Upvotes: 1
Views: 109
Reputation: 195
This work for me.
for(var a in model)
{
var model2=model[a].UserViews;
for (var k in model2)
{
alert(model2[k]);
}
}
Upvotes: 0
Reputation: 83358
You were close. Just stop here:
$.each(userDetails, function() {
but add parameters
$.each(userDetails, function(key, value) {
inside of the callback you'll have access to each property name in the object, as well its corresponding value.
$.each(userDetails, function(key, value) {
console.log(key, value, userDetails[key], userDetails[key] === value);
});
Here's a working fiddle
Upvotes: 1