0

プラグインでデフォルト値の1つを割り当てる必要がある特定のタグからXMLファイルで最高値を見つける機能があります。私の問題は、プラグイン コードが他の関数の前に実行されるため、null 値が返されることです。get_Highest_Property_Prise()Java コンストラクターのように、プラグインの前に関数を実行できますか? または、プラグイン コードが開始される前にグローバル変数を初期化する方法はありますか?

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 

});
}
4

1 に答える 1

1
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()

})
于 2013-05-30T21:20:43.703 に答える