K.Z
K.Z

Reputation: 5075

call function before plugin function starts

I have a function to find highest value in an XML file from certain tag which has to assign one of default value in plugin. My problem is my plugin code runs before the other function hence a null value is returned. Can I run function get_Highest_Property_Prise() before plugin, like java constructor? Or some how initialize a global variable before plugin code kicks in?

var pulgin_Global_Variables = {
    hight_price: ""
};

(function($) {

$.fn.SearchProperty = function (options) {

    var defaults = {
        S_MinPrice: 0,
        S_MaxPrice: get_Highest_Property_Prise()
    };

     alert("yo yo "+defaults.S_MaxPrice);
}
})(jQuery);


function get_Highest_Property_Prise()
{


$.get('Data.xml', function (XML_property) {

    $(XML_property).find('property').each(function () {

        var c_Price = parseInt($(this).find('priceask').text().replace(',', ''));

        if (c_Price > pulgin_Global_Variables.hight_price) {

            pulgin_Global_Variables.hight_price = c_Price;
        }
    }); //end of function 

});
}

Upvotes: 0

Views: 99

Answers (1)

James Daly
James Daly

Reputation: 1386

var pulgin_Global_Variables = {
    hight_price: ""
};  

  $.fn.SearchProperty = function (options) {

    var defaults = {
        S_MinPrice: 0,
        S_MaxPrice: pulgin_Global_Variables.hight_price
    };

     alert("yo yo "+defaults.S_MaxPrice);
}
})(jQuery); 



//here set max price to match your global object
 $.get('Data.xml', function (XML_property) {
        $(XML_property).find('property').each(function () {

            var c_Price = parseInt($(this).find('priceask').text().replace(',', ''));

            if (c_Price > pulgin_Global_Variables.hight_price) {

                pulgin_Global_Variables.hight_price = c_Price;

            }
        }); //end of function 

    }).done(function () {
       $(whatever).SearchProperty()

})

Upvotes: 1

Related Questions