passing the function parameter value to the function inside that function

Sizzling Code

I have this script which works fine but i want it to move to common js file.

function commonSelect2(selector,url,id,text){
    selector.select2({
        minimumInputLength:1,
        placeholder:"Select Parent Menu",
        ajax: {
            type:"post",
            url: url,
            dataType: 'json',
            quietMillis: 100,
            data: function(term, page) {
                return {
                    term: term, //search term
                    page_limit: 10 // page size
                };
            },
            results: function(data, page ) {
                var newData = [];
                $.each(data, function (index,value) {
                    newData.push({
                        id: value.id,  //id part present in data
                        text: value.text  //string to be displayed
                    });
                });
                return { results: newData };
            }
        }
    });
}

mostly it is done except the part of id and text parameter.

Here is how i send parameters

var selector = $('#selectParentMenu');
var url = "{{base_url()}}admin/configurations/loadAllParentFormNames/";
var id = "FormID";
var text = "FormName";
commonSelect2(selector,url,id,text);

problem is that

id: value.id,  //id part present in data
text: value.text  //string to be displayed

the value.id and value.text do not recognize the id and text is of parameters.

it works if i do like this

id: value.FormID,  //id part present in data
text: value.FormName  //string to be displayed

but if i put parameters containing these values don't work.

grin0048

Your id and text parameters are strings containing the names of the properties you are trying to access in your value object. To access properties dynamically like that requires the value[id] syntax.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing in a function as a function parameter

From Dev

Passing function with default parameter value as template parameter

From Dev

Passing struct parameter to a function inside a struct

From Dev

Passing a Function into a Parameter of Another Function

From Dev

Passing HTML input value as a JavaScript Function Parameter

From Dev

Passing parameter value to Function or Procedure with random order

From Dev

getopts passing value of declared parameter to function

From Dev

Passing parameter value to Function or Procedure with random order

From Dev

Passing a class as function parameter

From Dev

Passing callback function as parameter

From Java

Passing function as a parameter in java

From Dev

Passing a parameter to a callable function

From Dev

Passing matrix as a parameter in function

From Dev

Passing a function to a parameter in elisp

From Dev

Passing function invocation as a parameter

From Dev

Passing a function as a parameter CPP

From Dev

A function in JS with parameter passing

From Dev

Passing a parameter to a function

From Dev

Passing lazy function as parameter

From Dev

passing parameter to function

From Dev

Passing an animation function as a parameter

From Dev

Passing a parameter into a reducer function

From Dev

Passing a parameter in a nested function

From Dev

Passing this as a parameter to an angularjs function

From Dev

Passing this as a parameter to a function

From Dev

passing parameter to function

From Dev

Passing lazy function as parameter

From Dev

PowerShell passing function as parameter

From Dev

Passing template class as template template parameter inside class member function

Related Related

HotTag

Archive