-1

this is a html canvas using konva library.

var json = 'http://pastebin.com/Qv1HAUmY' this is my json data,

then before i get the value of "json" all item like this are deleted

{
            "attrs": {
                "stroke": "#666",
                "fill": "#ddd",
                "radius": 8,
                "name": "topLeft anchor",
                "draggable": true,
                "dragOnTop": false,
                "visible": false,
                "id": "ResizeAnchor"
            },
            "className": "Circle"
        }, {
            "attrs": {
                "x": 93,
                "stroke": "#666",
                "fill": "#ddd",
                "radius": 8,
                "name": "topRight anchor",
                "draggable": true,
                "dragOnTop": false,
                "visible": false,
                "id": "ResizeAnchor"
            },
            "className": "Circle"
        }, {
            "attrs": {
                "x": 93,
                "y": 104,
                "stroke": "#666",
                "fill": "#ddd",
                "radius": 8,
                "name": "bottomRight anchor",
                "draggable": true,
                "dragOnTop": false,
                "visible": false,
                "id": "ResizeAnchor"
            },
            "className": "Circle"
        }, {
            "attrs": {
                "y": 104,
                "stroke": "#666",
                "fill": "#ddd",
                "radius": 8,
                "name": "bottomLeft anchor",
                "draggable": true,
                "dragOnTop": false,
                "visible": false,
                "id": "ResizeAnchor"
            },
            "className": "Circle"
        }

i want to remove all anchor using JavaScript if possible.

zipzit
  • 3,778
  • 4
  • 35
  • 63
mmativ
  • 1,414
  • 14
  • 25
  • 1
    `all item like this are deleted` - what? you want to get rid of any `attrs` that have a name with `anchor` in it, or just the string `anchor` in the property `name` ? ... I suspect it will be easier to do so AFTER you parse the JSON to a variable – Jaromanda X Jan 15 '16 at 05:57
  • What exactly are you trying to do? This question is not clear at all. – zipzit Jan 15 '16 at 06:00
  • Suggestion: review the steps at http://stackoverflow.com/help/how-to-ask The problem with attempting to answer your question is we don't know what's generating the anchor content. If we had a remote glimpse of what goal you are trying to accomplish it would go a long way in obtaining help. Its easy to remove elements from a JSON object, but if those elements are automatically generated the removal is flawed and doomed to fail. Ask your question well, so somebody can understand what you are trying to do. Hint: it helps to respond to comments too! – zipzit Jan 15 '16 at 07:30

1 Answers1

0

At first i think it is a shame that peoples questions get downvoted because the average user of stackoverflow can't see the problem in less than 5 seconds...

Anyway i think what you want to say you have a var called "json" which holds the json data from the link. Now you want to delete all anchors from the data.

The only problem i have with your question is that i can't see what in your json is an anchor and what is not, but here is a little snippet that might help you:

var json = '.......'; // your json data
var jsObj = eval('(' + json + ')'); // eval the json to an object
for (var property in jsObj) // iterate through all members of the object
{
    if (property == 'anchor') // when you got your anchor
    {
        delete jsObj[property]; // delete the property
    }
}

This is just an example how you can clean your json. Now you should be able to clean it under the conditions you need.

DavidVollmers
  • 677
  • 5
  • 17
  • in my json data i want to delete all "attrs" with "topLeft/topright/bottomright/bottomleft anchor" because thats is the default anchor of my resizing functions, this is my little project, http://dota2nation.com/project/area51/loader.html and try to "save to json" you wil seel that the default anchor are still there and have a new generated anchor. thats why i want to delete it before load so i have new anchor per loading and delete old one, – mmativ Jan 15 '16 at 06:56
  • @4382610 - downvotes are not necessarily because the downvoter can't understand the question - sometimes the downvote is because the question is more or less in the form "give me code to do this" - which is generally unacceptable – Jaromanda X Jan 18 '16 at 03:05