Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

javascript - Javascript / Chrome - 如何从webkit检查器复制对象作为代码(Javascript / Chrome - How to copy an object from the webkit inspector as code)

I am doing a console.log statement in my javascript in order to log a javascript object.

(我在我的javascript中做一个console.log语句,以便记录一个javascript对象。)

I'm wondering if there's a way, once that's done - to copy that object as javascript code.

(我想知道是否有办法,一旦完成 - 将该对象复制为javascript代码。)

What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server.

(我要做的是转换使用ajax创建的对象将xml提要解析为静态javascript对象,以便文件可以在本地运行,而无需服务器。)

I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.

(我在chrome检查器窗口中包含了对象的屏幕截图,以便您可以看到我正在尝试做的事情。)

在此输入图像描述   ask by mheavers translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu.

    (右键单击Chrome控制台中的对象,然后从上下文菜单中选择“ Store as Global Variable ”。)

    It will return something like temp1 as the variable name.

    (它将返回类似temp1的变量名称。)

  2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.

    (Chrome还有一个copy()方法,因此控制台中的copy(temp1)应该将该对象复制到剪贴板。)

在Chrome DevTools中复制Javascript对象

Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object] .

(关于递归对象的注意事项:如果您正在尝试复制递归对象,您将获得[object Object] 。)

This is to be expected.

(这是可以预料的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...