Изменение текста диапазона внутри элемента, не работающего, используя jQuery - PullRequest
0 голосов
/ 11 февраля 2020

Я пытаюсь изменить текст диапазона. Внутри элемента dropzone. Проблема в том, когда я хочу сделать это глобально, как это:

$('.resolutie').text(obj[0].dpi + 'DPI');

Это работает нормально (но это не то, что я хочу, потому что он изменяет все классы, когда есть несколько элементов). Но если я попробую это:

$(this).next('.resolutie').text(obj[0].dpi + 'DPI');

Он перестает работать. Я пробовал несколько вещей. Они тоже:

$(this).find('.resolutie').text(obj[0].dpi + 'DPI');
$(this).next('.resolutie').text(obj[0].dpi + 'DPI');
$(this + '.resolutie').text(obj[0].dpi + 'DPI');

Но ничего из этого не работает.

Мой код находится внутри дропзоны, поэтому мой общий код выглядит следующим образом:

$('.dropzone').each(function(index){
    $maxfiles = $(this).attr('maxfiles'); <<<< this works, so why not the rest with $(this) ?
    $(this).dropzone({
        paramName: 'postedFile',
        addRemoveLinks: true,
        dictDefaultMessage: 'Sleep je bestand(en)',
        dictRemoveFile: 'Verwijder',
        dictCancelUpload: 'Annuleren',
        dictInvalidFileType: 'Dit type bestand is niet toegestaan',
        dictCancelUploadConfirmation: 'Weet je zeker dat je het uploaden wilt annuleren?',
        dictMaxFilesExceeded: 'Maximale aantal bestanden overschreden',
        maxFiles: $maxfiles,
        acceptedFiles: '.jpg, .jpeg, .png, .pdf, .tif, .tiff',
        thumbnailWidth: '150',
        thumbnailHeight: '120',
        thumbnailMethod: 'crop',
        previewTemplate: $(".hiddendiv").html(),
        // File contains dropzone file object, response contains ajax response from php file
        success: function (file, response) {
            var obj = JSON.parse(response);
            $(this).next('.resolutie').text(obj[0].dpi + 'DPI');
        },
    })
});

Это вся разметка HTML, если это полезно:

<form action="upload/uploaden.php" class="dropzone dz-clickable dz-started dz-max-files-reached" maxfiles="1" id="dropzone4">
   <input type="hidden" value="Monomeer" name="productnaam">
   <input type="hidden" value="Twan" name="klantnaam">
   <input type="hidden" value="20" name="hoogte">
   <input type="hidden" value="20" name="breedte">
   <div class="dz-default dz-message"><span>Sleep je bestand(en)</span></div>
   <div class="dz-preview dz-processing dz-image-preview dz-complete">
      <div class="dz-image"><img data-dz-thumbnail="" alt="Untitled-4.jpg"></div>
      <div class="dz-details">
         <div class="dz-size"><span data-dz-size=""><strong>0.1</strong> MB</span></div>
         <div class="dz-filename"><span data-dz-name="">Untitled-4.jpg</span></div>
      </div>
      <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress="" style="width: 100%;"></span></div>
      <div class="dz-error-message"><span data-dz-errormessage=""></span></div>
      <span class="toewijzen">Aantal toewijzen</span>
      <div class="uploadcontent">
         <input type="text" class="fileinput">
         <button class="plusminupload" id="minupload">−</button>
         <button class="plusminupload" id="plusupload">+</button>
      </div>
      <hr class="uploadline">
      <span class="infoline"><span class="infospan resolutie">Resolutie:</span> <i class="fas fa-check-circle goedgekeurd"></i></span>
      <span class="infoline"><span class="infospan formaat">Formaat:</span> <i class="fas fa-times-circle afgekeurd"></i></span>
      <button class="yellowbtn btn vrijgevenbtn" type="button">Bestand vrijgeven</button>
      <a class="dz-remove" href="javascript:undefined;" data-dz-remove="">Verwijder</a>
   </div>
</form>

1 Ответ

1 голос
/ 11 февраля 2020

Вы используете this внутри function, поэтому this - это не ваш объект, а сама функция. попробуйте установить var $this = this во внешней функции, затем в функции успеха используйте $this.find('resolutie')

$('.dropzone').each(function(index){
    $maxfiles = $(this).attr('maxfiles'); <<<< this works, so why not the rest with 
    var $this = $(this);
    $(this) ?
    $(this).dropzone({
        paramName: 'postedFile',
        addRemoveLinks: true,
        dictDefaultMessage: 'Sleep je bestand(en)',
        dictRemoveFile: 'Verwijder',
        dictCancelUpload: 'Annuleren',
        dictInvalidFileType: 'Dit type bestand is niet toegestaan',
        dictCancelUploadConfirmation: 'Weet je zeker dat je het uploaden wilt annuleren?',
        dictMaxFilesExceeded: 'Maximale aantal bestanden overschreden',
        maxFiles: $maxfiles,
        acceptedFiles: '.jpg, .jpeg, .png, .pdf, .tif, .tiff',
        thumbnailWidth: '150',
        thumbnailHeight: '120',
        thumbnailMethod: 'crop',
        previewTemplate: $(".hiddendiv").html(),
        // File contains dropzone file object, response contains ajax response from php file
        success: function (file, response) {
            var obj = JSON.parse(response);
            $this.find('.resolutie').text(obj[0].dpi + 'DPI');
        },
    })
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...