2017-02-27 14 views
0

私はRESTサンドボックスAPIを使用して状態配列から "呼び出し"を削除しています。配列には、それを削除するために何を使用するのかわからないすべてのJSONが含まれています。json要素を配列から削除するにはどうすればよいですか?

注記:これは、HTTP経由のLuaスクリプト実行要求からの接続です。

ウェブサイト:

//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'); 
 
})

+0

私はあなたを考えるgetsandbox.com

ここでコードがありますおそらく 'c alls.pop(); '、「それは私に許されませんが」コードのどの部分がうまくいかないかを私に教えてくれません。 – 4castle

+0

削除/削除が必要な要素をどのように特定していますか?サブキーの値は?あなたの提供しているコードで、要素を削除しようとしていますか?何を試しましたか? – haxxxton

答えて

2

callindexを見つけて、次を使用します:

calls.splice(index, 1); 
+0

どうすればいいですか?JSON – Dubst3p

+0

@ Dubst3pが含まれていればindexOfできます.jsonのテキストをjavascriptオブジェクトに変換して検索するには 'JSON.parse(jsonData) 'を使用できます。 – Amir

+0

@ Dubst3p、それは動作しましたか? – Amir

関連する問題