将JSON编码值解析为字符串,布尔值等

时间:2012-06-01 13:31:56

标签: javascript json localization

我有一个已经本地化的JSON编码对象,最终将为选项填写JS文件。选项的预期输出是(默认值和它所寻找的“类型”的解释):

jQuery(window).load(function() {
    jQuery('.flexslider').flexslider({
        animation: "fade",              //String: Select your animation type, "fade" or "slide"
        slideDirection: "horizontal",   //String: Select the sliding direction, "horizontal" or "vertical"
        slideshow: true,                //Boolean: Animate slider automatically
        slideshowSpeed: 7000,           //Integer: Set the speed of the slideshow cycling, in milliseconds
        animationDuration: 600,         //Integer: Set the speed of animations, in milliseconds
        directionNav: true,             //Boolean: Create navigation for previous/next navigation? (true/false)
        controlNav: true,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
        keyboardNav: true,              //Boolean: Allow slider navigating via keyboard left/right keys
        mousewheel: false,              //Boolean: Allow slider navigating via mousewheel
        prevText: "Previous",           //String: Set the text for the "previous" directionNav item
        nextText: "Next",               //String: Set the text for the "next" directionNav item
        pausePlay: false,               //Boolean: Create pause/play dynamic element
        pauseText: 'Pause',             //String: Set the text for the "pause" pausePlay item
        playText: 'Play',               //String: Set the text for the "play" pausePlay item
        randomize: false,               //Boolean: Randomize slide order
        slideToStart: 0,                //Integer: The slide that the slider should start on. Array notation (0 = first slide)
        animationLoop: true,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
        pauseOnAction: true,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
        pauseOnHover: false,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
        controlsContainer: "",          //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
        manualControls: "",             //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
        start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
        before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
        after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
        end: function(){}               //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
    });
});

我当前的JSON编码对象的HTML输出是:

/*<![
    CDATA[
        */varflexslider_vars=[

        ];flexslider_vars={
            "js_animation": "fade",
            "js_slide_direction": "horizontal",
            "js_slideshow": "1",
            "js_slideshow_speed": "7000",
            "js_animation_duration": "600",
            "js_direction_nav": "1",
            "js_control_nav": "1",
            "js_keyboard_nav": "1",
            "js_mousewheel": null,
            "js_prev_text": "Prevous",
            "js_next_text": "Next",
            "js_pause_play": null,
            "js_pause_text": "Pause",
            "js_play_text": "Play",
            "js_randomize": null,
            "js_slide_start": "0",
            "js_animation_loop": "1",
            "js_pause_on_action": "1",
            "js_pause_on_hover": null,
            "js_controls_container": "",
            "js_manual_controls": "",
            "js_start_function": "function(){}",
            "js_before_function": "function(){}",
            "js_after_function": "function(){}",
            "js_end_function": "function(){}"
        };/*
    ]
]>*/

这就是我目前(并且不成功地)将这些选项添加到JS文件的方式:

jQuery(window).load(function() {
    jQuery('.flexslider').flexslider({
        animation: flexslider_vars.js_animation,              //String: Select your animation type, "fade" or "slide"
        slideDirection: flexslider_vars.js_slide_direction,   //String: Select the sliding direction, "horizontal" or "vertical"
        slideshow: flexslider_vars.js_slideshow,                //Boolean: Animate slider automatically
        slideshowSpeed: flexslider_vars.js_slideshow_speed,           //Integer: Set the speed of the slideshow cycling, in milliseconds
        animationDuration: flexslider_vars.js_animation_duration,         //Integer: Set the speed of animations, in milliseconds
        directionNav: flexslider_vars.js_direction_nav,             //Boolean: Create navigation for previous/next navigation? (true/false)
        controlNav: flexslider_vars.js_control_nav,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
        keyboardNav: flexslider_vars.js_keyboard_navjs_mousewheel,              //Boolean: Allow slider navigating via keyboard left/right keys
        mousewheel: flexslider_vars.js_mousewheel,              //Boolean: Allow slider navigating via mousewheel
        prevText: flexslider_vars.js_prev_text,           //String: Set the text for the "previous" directionNav item
        nextText: flexslider_vars.js_next_text,               //String: Set the text for the "next" directionNav item
        pausePlay: flexslider_vars.js_pause_play,               //Boolean: Create pause/play dynamic element
        pauseText: flexslider_vars.js_pause_text,             //String: Set the text for the "pause" pausePlay item
        playText: flexslider_vars.js_play_text,               //String: Set the text for the "play" pausePlay item
        randomize: flexslider_vars.js_randomize,               //Boolean: Randomize slide order
        slideToStart: flexslider_vars.js_slide_start,                //Integer: The slide that the slider should start on. Array notation (0 = first slide)
        animationLoop: flexslider_vars.js_animation_loop,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
        pauseOnAction: flexslider_vars.js_pause_on_action,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
        pauseOnHover: flexslider_vars.js_pause_on_hover,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
        controlsContainer: flexslider_vars.js_controls_container,          //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
        manualControls: flexslider_vars.js_manual_controls,             //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
        start: flexslider_vars.js_start_function,            //Callback: function(slider) - Fires when the slider loads the first slide
        before: flexslider_vars.js_before_function,           //Callback: function(slider) - Fires asynchronously with each slider animation
        after: flexslider_vars.js_after_function,            //Callback: function(slider) - Fires after each slider animation completes
        end: flexslider_vars.js_end_function              //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
    });
});

所以 - 问题本身并没有调用选项(看起来工作正常),它正在根据JS文件所需的值改变实际输出(字符串,布尔值,整数等),因为从右到右现在,它因为它而蹲下了。我很欣赏正确方向的任何推动。谢谢!

0 个答案:

没有答案