• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

162
Views
Adding another variable into template literal variable

How do I use a variable to make the following code reusable? Can I embed a variable in a template literal variable?

I am getting an object from the endpoint and I want to access object.CategoryName

here is my current code

export default function getCategoryAll(url, appendId, dataTitle, dataBody) {
    return $.ajax({
        url: url,
        type: 'GET',
        data: {

        },
        success: function (data) {
            console.log(data);
            // work here
            data.map((data) => {
                $(`#${appendId}`).append(`
                <div class="items-list-container">
                    <div class="items-list-content">
                    <div class="h5 items-list-content-title">${data + "." + dataTitle}}</div>
                    <div class="items-list-content-body d-flex"></div>
                    <button class="items-list-update-button badge btn btn-outline-success">Update</button></div>
                </div>`)
                return data
            })
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // Empty most of the time...
            $('#setting-category-list').append("<h4>Error!</h4>")
        }
    });
}

getCategoryAll("/getCategoryAll", "setting-category-list", "CategoryName")
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error