Javascript如何从对象中读取 [英] Javascript how to read from an object

查看:86
本文介绍了Javascript如何从对象中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Jscript.net新手,我正在尝试读取一个对象,但我现在不知道对象x到底是什么.
实际上,我从共享点站点成功读取了其他一些valeus,但是事实证明,唯一失败的变量是x,事实证明x是一个对象.起初,我以为[object Object]不会返回任何东西,直到我进行了网络跟踪为止.要封装在对象内的x接缝的值.但是我不知道如何从一个对象中得到我的价值.

如果我

i am a Jscript.net newbie i am trying to read an object I do not k now exactly what the object x is.
in fact i read some other valeus successfully from a sharepoint site, but it turns out the only variable that fails is x, it turns out that x is an object. At first i thought [object Object] didnt return anything untill i did a network trace; the values of x seam to be encapsulated inside an object. But i dont know how to get my values out of an object.

if i do

alert(x);


我得到结果: [对象对象]

如果我


I get result : [object Object]

if i do

alert("myObject is " + x.toSource());  // but this works only in firefox 


我得到结果:({$ L_1:3,$ b_1:"tpc-102"})


我想要得到的就是这些值.
不仅可以在Firefox中工作,还可以在Internet Explorer中工作

3
tpc-102

最好为它们分配一些变量,例如
a = 3
b = tpc-102



如果您想回答这个问题,请帮助我发掘这些价值观;将我指向许多网站和书籍可能是以后的想法.我不害怕学习,但是我已经读了很多书,但我都没有发现[对象对象]问题.甚至与Google一起寻找都没有给我任何提示.


I get result : ({$L_1:3, $b_1:"tpc-102"})


What i want to get in return is just these values.
And working in not only firefox also internet explorer

3
tpc-102

preferably having some variables assigned to them like
a = 3
b = tpc-102



If you like to answer this help me to get these values out; pointing me to many websites and books is maybe an idea for later; i''m not afraid of learning but i consumed a lot books allready in none of these i found the [object Object] problem. And even looking with google didnt gave me clues.

推荐答案

L_1:3,


b_1:"tpc-102"} )


我想要得到的就是这些值.
不仅可以在Firefox中工作,还可以在Internet Explorer中工作

3
tpc-102

最好为它们分配一些变量,例如
a = 3
b = tpc-102



如果您想回答这个问题,请帮助我发掘这些价值观;将我指向许多网站和书籍可能是以后的想法.我不害怕学习,但是我已经读了很多书,但我都没有发现[对象对象]问题.甚至连Google都没有给我提示.
b_1:"tpc-102"})


What i want to get in return is just these values.
And working in not only firefox also internet explorer

3
tpc-102

preferably having some variables assigned to them like
a = 3
b = tpc-102



If you like to answer this help me to get these values out; pointing me to many websites and books is maybe an idea for later; i''m not afraid of learning but i consumed a lot books allready in none of these i found the [object Object] problem. And even looking with google didnt gave me clues.


首先,为什么不解释x是什么?如果这是您的类的对象,则应该更好地显示代码,以及如何获取此对象.

然后,如果您知道自己的代码或文档中对该对象有什么期望,则只需调用其方法和属性即可.

最后,如果您没有此信息,则可以使用JavaScript使用 Reflection ( http ://en.wikipedia.org/wiki/Reflection_(computer_programming) [ ^ ], http://en.wikipedia.org/wiki/Reflection_ %28computer_programming%29#ECMAScript [ ^ ]),然后找出所有对象的成员.参见:
http://lpetr.org/blog/archives/reflection-in-javascript [ ^ ],
http://stackoverflow.com/questions/275351/javascript-reflection [> http://stackoverflow.com/questions/5208784/reflecting-within-a-javascript-function [ ^ ],
http://stackoverflow.com/questions/7447117/javascript-reflection-to-find-prototype-methods-global-scope-methods-and-object [
First of all, why did not you explain what x is? If this is the object of your class, you should have better show the code, how did you get this object.

Then, if you know what to expect from this object from your own code or documentation, you could just call its methods and properties.

Finally, if you don''t have this information, with JavaScript you can use Reflection (http://en.wikipedia.org/wiki/Reflection_(computer_programming)[^], http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29#ECMAScript[^]) and find out all object''s members. See:
http://lpetr.org/blog/archives/reflection-in-javascript[^],
http://stackoverflow.com/questions/275351/javascript-reflection[^],
http://stackoverflow.com/questions/5208784/reflecting-within-a-javascript-function[^],
http://stackoverflow.com/questions/7447117/javascript-reflection-to-find-prototype-methods-global-scope-methods-and-object[^].

—SA


这篇关于Javascript如何从对象中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆