2013-02-25 1 views
2

나는 새로운 미디어 업 로더의 기본 인스턴스에서 선택을 얻기 위해 노력하고 있어요 ...워드 프레스에서 선택을 얻는 방법 3.5 미디어 업 로더

나는 그렇게 내가 사용하고 있지 않다 기본적으로 표시하는 방법과 행복 -

file_frame = wp.media.frames.file_frame = wp.media(
{ 
    title: 'Select File', 
    button: { 
     text: jQuery(this).data('uploader_button_text') 
    }, 
    multiple: false 
}); 

그냥

wp.media.editor.open(); 

그래서이

분명히 작동하지 않습니다

하지만 어느 쪽도이

wp.media.editor.state().get('selection').first().toJSON(); 

또는이

wp.media.state().get('selection').first().toJSON(); 

그래서 코드는 내가 무엇을 사용해야한다하지 않는다? 누군가까지이에 해키 솔루션을 확인

+0

896의 media-models.js에 내가 필요한 것을 반환하지만 이것이 '선택 : 단일'수신 대기하도록 청취자를 바인딩 할 수 없습니다. - this._single.trigger ('selection : single ', this._single, this); 나는 '나에게'이것 '이 –

+0

wp.media.controller.state()를 가리키는 것을 해결할 수 없다. ('selection ') get이 작동하지 않는다. 나는 지금 수백 가지를 시도했다. 나는 'selection : single'이 this.controller.state(). get ('selection')을 트리거하지만 이것이 무엇을 가리키는 지 알 수 없다. –

+0

wp.media.view.Attachment.controller.state() .get ('selection')이 작동하지 않습니다. –

답변

0

거기에 희망이 있기 때문에 우리가 얼마나 걸릴지 모릅니다 이후의 setTimeout의

jQuery('.media-modal .type-image').on('click',function(index, element) { 
var thisCollection = wp.media.model.Query.all._byCid; 
setTimeout(function() { //we need this becuse the details area is not generated until after the click 
    var thisEditUrl = jQuery('.details .edit-attachment').attr('href'); 
    var attachId = thisEditUrl.match(/post=([^&]+)/)[1]; 
    var attachmentAtts = ''; 
    jQuery.each(thisCollection, function(index,item) { 
     if(this.id == attachId) 
      attachmentAtts = this.attributes; 
    }); 
},500); 
}); 

그 이상적이지 ... 제대로하는 방법을 게시 할 수 있습니다 .details 영역이 채워지지만 시도한 지 하루 반 후에 나는 다른 방법으로는 해결할 수 없습니다.

희망이 거기에 누군가가이 권리를하는 방법을 알고, ... 보장은 그래도 작동하지 않습니다))

1

당신은 다중 선택이 뭔가를 (시도 할 수 :

var selection = wp.media.editor.state().get('selection'); 

var attachment_ids = selection.map(function(attachment) { 
    attachment = attachment.toJSON(); 
    return attachment.id; 
}).join(); 
+0

쿨하고, 피드백을 피드백 해드립니다. –

1

: https://wordpress.stackexchange.com/questions/87357/wordpress-media-manager-3-5-default-link-to

다음 this.controller.state().get('selection') 액세스를 제공 wp.media.view.Settings.AttachmentDisplayrender의 기능을 확장 여기에서 응답 적응

function($) { 
    var _AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay; 
    wp.media.view.Settings.AttachmentDisplay = _AttachmentDisplay.extend({ 
     render: function() { 
     _AttachmentDisplay.prototype.render.apply(this, arguments); 
     selection = this.controller.state().get('selection').first().toJSON(); 
    //now, for example: 
     filename = selection.filename; 
     } 
    }); 
})(); 
0

나는 이것이 오래된 스레드라는 것을 알고 있지만 여러 파일을 업로드 할 때 모든 첨부 파일 ID를 얻기위한 Google 검색에서이를 발견했습니다.

나는 약간 완벽하게 작동하기 Adal의 답변을, 적응 :

   var selection = wp.media.state().get('selection'); 

       var attachment_ids = selection.map(function(attachment) { 
        attachment = attachment.toJSON(); 
        return attachment.id; 
       }).join(); 

하기 Adal 다시 그 대답에 대한 피드백이 없어 (그리고 내가 떠날 수있는 충분한 명성을하지 않는 한 그냥 참고로이 추가 아직 댓글이 없습니다.)