因此,我使用 REST 沙箱 API 从状态数组中删除“Call”,并且该数组包含所有 JSON,不确定使用什么来删除它。
请注意:这是通过 HTTP 从 Lua 脚本运行的请求进行连接。
网站:getsandbox.com
代码如下:
//Store Calls
state.calls = state.calls || []
var calls = state.calls;
/*
|
| Create Call
V
*/
Sandbox.define('/new/call/','POST', function(req, res){
var gameid = req.get("Roblox-Id");
var person = req.body.split(" ")[0];
var reason = req.body.split(" ")[1];
var comp = {
gameid: gameid,
player: person,
callreason: reason
};
calls.push(comp);
// Set the type of response, sets the content type.
res.type('text/plain');
// Set the status code of the response.
res.status(200);
// Send the response body.
res.send('Request Accepted');
});
/*
|
| Get Calls
V
*/
Sandbox.define('/get/calls/','GET', function(req, res){
// Check the request, make sure it is a compatible type
// Set the type of response, sets the content type.
res.type('application/json');
// Set the status code of the response.
res.status(200);
// Send the response body.
res.send(calls);
})
/*
|
| Delete
v
*/
Sandbox.define('/data/delete/{gameid}/','GET', function(req, res){
for(i=0;i<calls.length;i++){
calls[i].pop();
}
// Set the type of response, sets the content type.
res.type('text/plain');
// Set the status code of the response.
res.status(200);
// Send the response body.
res.send('Successful');
})
最佳答案
找到调用
的索引
并使用以下内容:
calls.splice(index, 1);
关于javascript - 如何从数组中删除 json 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42476388/