代码记录

$('#metadata-collection-update').select2({
        ajax: {
          url: '/Collections/GetCollectionsForUserBySearchTerm',
          processResults: function (result) {
            if (result.success) {
              return {
                results: result.data
              };
            }
            else {
              _messagebox.newNotify2(GlobalStringsForAssets.COLLECTION_NAME_RETRIEVAL_FAILED, "Error");
            }
          },
        },
        dropdownParent: $("#saveCollectionModal")
      })
      .on('change.select2', function () {
        var val = $(this).select2('data');
        if (val && val.length > 0) {
          $("#saveCollectionModal").find('#btnAddToExistingCollection').prop('disabled', false);
        }
      })
      .data('select2').$selection.css('height', '34px');
      $('#metadata-collection-update').select(function () {
        $('option:selected', this).remove();
      });
 
第二种写法:
        $('#metadata-collection-update').select2({
          ajax: {
            url: '/Collections/GetCollectionsForUserBySearchTerm',
            processResults: function (result) {
              if (result.success) {
                return {
                  results: result.data
                };
              }
              else {
                _messagebox.newNotify2(GlobalStringsForAssets.COLLECTION_NAME_RETRIEVAL_FAILED, "Error");
              }
            },
          },
          dropdownParent: $("#saveCollectionModal")
        }).data('select2').$selection.css('height', '34px')
        $('#metadata-collection-update').on("change", function () {
          if ($("#select2-metadata-collection-update-container").html() != '') {
            $("#saveCollectionModal").find('#btnAddToExistingCollection').prop('disabled', false);
          }
        })
        $("#saveCollectionModal").on("hidden.bs.modal", function () {
          $('#metadata-collection-update').val(null).trigger('change');
          $('#metadata-collection-update').hide();
        });
posted @ 2019-01-07 17:22  福慧榕  Views(109)  Comments(0Edit  收藏  举报