如何以字符串格式显示JavaScript对象的内容,就像我们alert变量一样?
我希望显示对象的格式相同的方式.
我有一个包含循环引用的JavaScript对象定义:它有一个引用父对象的属性.
它还具有我不想传递给服务器的功能.我如何序列化和反序列化这些对象?
我读过这样做的最好方法是使用Douglas Crockford的stringify.但是,我在Chrome中收到以下错误:
TypeError:将循环结构转换为JSON
代码:
function finger(xid, xparent){
this.id = xid;
this.xparent;
//other attributes
}
function arm(xid, xparent){
this.id = xid;
this.parent = xparent;
this.fingers = [];
//other attributes
this.moveArm = function() {
//moveArm function details - not included in this testcase
alert("moveArm Executed");
}
}
function person(xid, xparent, xname){
this.id = xid;
this.parent = xparent;
this.name = xname
this.arms = []
this.createArms = function () {
this.arms[this.arms.length] = new arm(this.id, this);
}
}
function group(xid, xparent){
this.id = …Run Code Online (Sandbox Code Playgroud) 我只是制作一个简单的应用程序来学习与redux的异步.我已经完成了所有工作,现在我只想在网页上显示实际状态.现在,我如何在render方法中实际访问商店的状态?
这是我的代码(一切都在一页,因为我只是在学习):
const initialState = {
fetching: false,
fetched: false,
items: [],
error: null
}
const reducer = (state=initialState, action) => {
switch (action.type) {
case "REQUEST_PENDING": {
return {...state, fetching: true};
}
case "REQUEST_FULFILLED": {
return {
...state,
fetching: false,
fetched: true,
items: action.payload
}
}
case "REQUEST_REJECTED": {
return {...state, fetching: false, error: action.payload}
}
default:
return state;
}
};
const middleware = applyMiddleware(promise(), thunk, logger());
const store = createStore(reducer, middleware);
store.dispatch({
type: "REQUEST",
payload: fetch('http://localhost:8000/list').then((res)=>res.json())
});
store.dispatch({ …Run Code Online (Sandbox Code Playgroud) 如果我喜欢网站的一个元素,并且我想将它实现到我的网站中,那么最简单的方法是什么?有时会有很多CSS文件,很难跟踪所有这些文件.
我正在使用Chrome开发工具,我正在挖掘网络窗格以查看带有预览选项卡的XHR响应.我想从预览中抓取一个特定的对象.但是当我尝试通过右键单击预览对象来存储为全局变量时,创建的临时变量为null.
我发现这很奇怪,因为数据在内存中(否则它根本不显示).这是一个相当大的响应数组的例子,我试图从中获取特定的对象.
为了澄清,我可以存储出现在我的控制台中的变量.但我无法从网络选项卡的预览窗格中存储变量.我正在忽略Chrome开发工具的任何功能,还是我被迫控制登录我的XHR响应并从那里拉出对象?
我真的不想console.log()在我的代码中添加任何或其他断点,只是为了以后必须删除它们.挖掘超长原始JSON响应也是不切实际的.我在Windows 7上使用Chrome 47.
javascript ×3
asynchronous ×1
css ×1
html ×1
jquery ×1
json ×1
react-redux ×1
reactjs ×1
redux ×1
stringify ×1