Converting Javascript object to jquery object?
when iam trying to convert javascript object to jquery object like obj = $(obj). The object obj is loosing one of the property values and setting the value as true.if iam using obj[0].Validated its returning the exact values.Please suggest on this.开发者_运维问答
obj = $(obj);
objValue = obj.attr("Validate");
Looking at your code, you basically have an array of objects since you mentioned being able to do:
obj[0].Validate
This means that when you convert your object to a jQuery object, you're still dealing with an array of objects.
Simply doing obj.attr('Validate')
will faily because you're not accessing a single object in your array yet.
Consider the following:
var x = {obj1 : {Validate: true, SomethingElse: false, AnotherProperty: true}};
var jQx = $(x);
var jQxFirst = $(jQx.attr('obj1'));
Here we can see that I have an collection of objects. In order to check my Validate
property I need to access the individual item in the object collection.
This will now work:
console.log(jQxFirst.attr('Validate'));
console.log(jQxFirst.attr('SomethingElse'));
console.log(jQxFirst.attr('AnotherProperty'))
Here's a working example: http://jsfiddle.net/48LWc/
Another example using a more familiar notation to indicate how we're dealing with an array:
http://jsfiddle.net/48LWc/1/
var objCollection = new Array();
objCollection[0] = {Validate: true, SomethingElse: false, AnotherProperty: true};
var jQx = $(objCollection);
var jQxFirst = $(jQx[0]);
精彩评论