簡體   English   中英

如何使用 jquery 將文本綁定到 JsonObj 中的 label

[英]How to bind text to the label which is in JsonObj using jquery

我在一個數組中獲取數據,我需要綁定到下面的 label 是我的代碼。 當數組為空時,我需要綁定沒有找到有效的記錄,但我需要將數組中的數據綁定到 label。 假設如果我在數組中有 2 個項目,我需要綁定兩個項目,即 slider 1 應該有一個項目,然后在向右滑動后再次綁定第二個項目。

如果有超過 1 個項目,則應啟用右側 slider,如果它只有 1 個項目,則應禁用 slider 如果沒有項目,則應禁用兩個滑塊

代碼

圖2

success: function (response) {
    var json = response.d;
    if (json.length == 0) {
        $('.swiper-wrapper').append('<div class="swiper-slide">No rocords found</div>');
    } else {
        $.each(json, function (index, item) {
            $('.swiper-wrapper').append('<div class="swiper-slide">Name : ' + item.Name + '<br />Number: ' + item.Number + '</div>');
        });
    }

你可以拋出一堆 if else 語句

if(length > 1) {
// there is more than one item
} else if(length < 1) {
// there is less than one item
else {
//there is exactly one item
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM