The output of JSTree's data.rslt.obj.text() function is an array of text values, not just the text from the specified node

I am facing an issue with the jstree where it is returning a concatenated list of node names when I try to rename a node, instead of just the text for the node I am renaming. The jstree is set up to load on demand. How can I ensure that only the text for the specific node being renamed is returned in the contextmenu? Any help would be greatly appreciated! Below is the complete jstree code:

        $("#RequirementsTree")
    .bind("select_node.jstree", function(event, data) {
            if(is_requirement_node(data))
            {
                var id = data.rslt.obj.attr("id");

                if(id != null)
                {
                    $("#RequirementsTree").jstree('close_all')
                }
                else {
                    alert("Requirement node select error");
                }
            }
     })
    .bind("create.jstree", function(e, data) {
        // Ajax call to Server with parent node id and new node text
        $.ajax({
            type: "POST",
            url: '@Url.Content("~/RMS/insertRequirementNode")',
            data: {
                    ParentID : ParentNode,
                    ChildNodeText : data.rslt.obj.text()
            },
            success: function(new_data) {
                $.jstree._reference($("#RequirementsTree")).refresh(-1);
                ParentNode = null;
                data = null;
                return new_data;
            }   
        });

        ParentNode = null;
        if (data.rslt.parent == -1) {
            alert("Can not create new root directory");
            // Rollback/delete the newly created node
            $.jstree.rollback(data.rlbk);
            return;
        }

        BranchReqFLag = null;
    }).bind("rename.jstree", function(e, data) {
            $.ajax({
                type: "POST",
                url: '@Url.Content("~/RMS/updateRMSHierarchyNode")',
                data: {
                    NodeID: ParentNode,
                    NodeText: data.rslt.obj.text()
                },
                success: function() {
                    ParentNode = null;
                    data = null;
                }
            });
    }).jstree({
        json_data: {
            data: RBSTreeModel,
            ajax: {
                type: "POST",
                data: function (n) {
                    return {
                        NodeID: n.attr("id").substring(4),
                        Level: n.attr("name").substring(7)
                    };
                },
                url: function (node) {
                    return "/Audit/GetRequirementsTreeStructure";
                },
                success: function (new_data) {
                    return new_data;
                }
            }
        },
        contextmenu: {
            items: function($node) {
                    return {
                        createItem : {
                            "label" : "Create New Branch",
                            "action" : function(obj) { 
                                this.create(obj); 
                                BranchReqFlag = "Branch"; 
                                ParentNode = obj.attr("id").substring(4);
                            },
                            "separator_before" : true
                        },
                        renameItem : {
                            "label" : "Rename Branch",
                            "action" : function(obj) { 
                                this.rename(obj);
                                BranchReqFlag = "Branch";
                                ParentNode = obj.attr("id").substring(4);
                            },
                            "separator_before" : true
                        }
                    };
            }
        },
        plugins: ["themes", "json_data", "ui", "crrm", "contextmenu"]
    });
});

Answer №1

data.rslt.new_name contains the newly entered name. By using Chrome or Firebugs to inspect data, you can uncover answers to many similar queries.


    }).bind("rename.jstree", function(e, data) {
            $.ajax({
                type: "POST",
                url: '@Url.Content("~/RMS/updateRMSHierarchyNode")',
                data: {
                    NodeID: ParentNode,
                    NodeText: data.rslt.new_name
                },
                success: function() {
                    ParentNode = null;
                    data = null;
                }
            });
    })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fetching the exchanged messages between the sender and recipient - utilizing MongoDB, Express, and React for chat functionality

I am dealing with two collections named students and teachers in the mongodb database. The structure of a conversation between a student and a teacher involves arrays of messages within each object, as well as the IDs of the sender and receiver. I am seeki ...

Unable to delete product from shopping cart within React Redux reducer

Currently, I am tackling the challenge of fixing a bug in the shopping cart feature of an e-commerce website I'm working on. The issue lies with the remove functionality not functioning as expected. Within the state, there are cartItems that can be ad ...

Unable to add key/value pair to object in Node

While using Node, I encountered a strange issue where I was unable to attach the key/value pair broadcastStamp = date to the object "result." Despite confirming that it is indeed an object with typeof, no errors were thrown - the key/value simply did not a ...

What is the best way to include and delete several images on a canvas?

Recently, I've started working with canvas in HTML5 and I'm tasked with creating a paint application. One of the features I need to implement is the ability to dynamically add selected images to the canvas as the mouse moves, and then have the fu ...

Retrieve the innerHTML contents from all span elements

I'm having trouble getting the content of all span tags that are child elements of div#parent. So far, I've only been able to retrieve the content of the first one. Can someone please assist me with this? $( document ).ready(function() { ...

Tips for accessing information from an Angular Resource promise

I am currently facing an issue when trying to read data from an angular promise that was returned. Before, I had the following code: var data = category.get({id:userid}); Later, I realized that the data being returned was an unresolved promise. So, I ma ...

The text sliding feature gradually moves further away from the left side with each iteration

I am in the process of transferring an existing slider from one website to another. Instead of creating a text slider from scratch, I decided to modify the code I found for the new site. However, the slider is not functioning correctly on the new site. Th ...

When the phone locks, Socket.io experiences a disconnection

setInterval(function(){ socket.emit("stayalive", { "room": room }); }, 5000); I have developed a simple browser application with an interval function that is currently running on my phone. I am using Chrome on my Nexus 4 for debugging purposes. However, ...

What is the method for calling a function in a JavaScript file?

I am facing a challenge with reinitializing a JavaScript file named AppForm.js after a successful ajax post response. Within the file, there are various components: (function(namespace, $) { "use strict"; var AppForm = function() { // Cr ...

Tips for preventing multiple counter buttons from conflicting with one another

Currently, I am in the process of creating an online restaurant platform that allows customers to place food orders. To streamline this process, I am developing individual cards for each food item available on the menu. In addition, I am implementing butto ...

Combining 2 JSON arrays by matching their keys

Is there a way to combine 2 JSON arrays using the same keys and add a third item from the input JSON, pog_id, into the output JSON file? I attempted to do this with the code below, but it seems to be creating two separate arrays within a key in the JSON in ...

Updated the object in an array retrieved from an API by adding a new key-value pair. Attempted to toggle the key value afterwards, only to find that

Essentially, I am retrieving products from an API and including a new key value isAdded in the object within the products array. I utilized a foreach loop to add that key and it was successfully added. Now, when I click the Add to cart button, the product ...

Unable to figure out why information is not being transferred to an array through Mongoose

Seeking assistance as I am unable to figure out how to place a set of information into an array named "teamDetails". Here is the relevant /post item from server.js: app.post('/create', (req, res) => { console.log('Post command receiv ...

Error message: "Issue encountered with locating Node import module while operating within a docker

I've created a React app along with a Node.js server that includes the following imports: import express from 'express' import compression from 'compression' import cookieParser from 'cookie-parser' import bodyParser from ...

Express.js encounters a 404 error when router is used

I am currently in the process of learning and consider myself a beginner at Node.js. My goal is to create a basic REST API, but I keep encountering an error 404 when attempting to post data to a specific route using Postman to test if the information has b ...

Is it necessary to clean up the string to ensure it is safe for URLs and filenames?

I am looking for a way to generate a URL-safe filename in JavaScript that matches the one created using PHP. Here is the code snippet I currently have in PHP: <?php $clean_name = strtr($string, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕ ...

Issue with jQuery select box (roblaplaca) and its custom scroll bar functionality not functioning as expected

Recently, I implemented the custom select box script from . This script allows for two select boxes, where the second one updates dynamically using AJAX when there is a change in the first select box. Below is a sample of the HTML code: <option>One& ...

Error: Improper hook call detected with no hooks being used (material-ui v5)

I've created the following basic application: import Grid from '@material-ui/core/Grid'; function App() { return ( <div className="App"> <Grid container spacing={2}> <Grid item xs={8}> ...

Storybook encounters an undefined error with the Vuex store

Here is a snippet from my main.js file: import './plugins'; import store from './store'; import FileUpload from './components/FileUpload'; export default { install(Vue) { Vue.component('file-upload', ...

Manipulate JSON data in PHP using arrays

I need some help with accessing a value from my JSON Array. Here is the PHP code I am using to retrieve the JSON content: $input = @file_get_contents("php://input"); $event_json = json_decode($input); $event = \Stripe\Event::retrieve($event_id); ...