1

I have a category list with subcategories, made with nestable.js. So I can easily drop and drag it to a new location. So I can easly make a category subcategory and vice versa. But Now after I changed a category field, I just want to remove or add the red button of the child/parents categories if needed.

For example, look at the picture below. What If I want to make the field "Gamma" a child of "Hubo? Then Gamma must get a red button and the red button for "Hubo" should be removed.

enter image description here

This is the code that I have so far, but it doesn't work...

 $.ajax({
            type: "POST",
            url: '{{route('admin.categories.save-nested-categories')}}',
            async: true,
            dataType: 'json',
            data: {nestableOutput: nestableOutput},
            success: function (response) {

                     console.log(response['name']);

                     var dataContents = [];
                     $('.dd-item').each(function() {
                     dataContents.push($(this).attr('data-content'));

                     });

                        for (let i = 0; i < dataContents.length; ++i) {
                            console.log(response['name'][i]);
                            console.log(dataContents);
                            if(JSON.stringify(dataContents[i]) == 'true' && JSON.stringify(response['name'][i]) == 'true'){
                             $("li[data-id='"+ (i+1) +"']").find('form').hide()
                            }

                        }

// in controller

  $categories = Category::all();

    $disables = [];

    foreach($categories as $category){
        if($category->subcategory->count() == 0){
            array_push($disables, true);
        } else{
            array_push($disables, false);
        }

    }

    return response()->json(['name' => $disables]);
}



 

0 Answers0