Sitecore дает значения и мне нужно добавить в jQuery - PullRequest
0 голосов
/ 04 июня 2019

Мне нужно добавить значения sitecore в текущих и потенциальных местах. Можете ли вы прочитать значения, используя .pointerValue в jQuery?

Мы должны прочитать значение, используя html label или, добавив метку с классом.

enter image description here enter image description here

Как читать значения в jQuery?

jQuery(document).ready(function () {

    var currentValue = 30;         

    if (currentValue > 0 && currentValue <= 20) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgG');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    else if (currentValue >= 21 && currentValue <= 38) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgF');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    else if (currentValue >= 39 && currentValue <= 54) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgE');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    //Potential Value Starts
    var potentialValue = 50;

    if (potentialValue > 0 && potentialValue < 20) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgG');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    else if (potentialValue > 21 && potentialValue < 38) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgF');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    else if (potentialValue > 39 && potentialValue < 54) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgE');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    //Potential Value Ends
});

1 Ответ

0 голосов
/ 05 июня 2019

Как я предположил в своем комментарии, .text() может использоваться как и для получения, так и для установки. Например, вы можете прочитать значение следующим образом:

var pv = parseInt(jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text().trim());

parseInt() преобразует значение String в целое число. Пример: parseInt("43") вернет тип Int со значением 43.

.text() будет читать TextNode из объекта <span class="pointerValue">43</span>, это приведет к String "43".

.trim() удалит все пробелы из объекта String, если они найдены. Вам не нужно его использовать.

Итак, .text().trim() прочитает строку "43" и передаст ее parseint(), которая наберет приведение к целому числу 43 и сохранит ее в переменной pv.

Надеюсь, это поможет. Если вам нужна дополнительная помощь, опубликуйте более полный пример.

...