2011-12-02 2 views
1

JSON 파일에 내 콘텐츠가 있고 싶습니다. 내 모달 창을 동적으로 채 웁니다. 언제든지 해당 링크를 클릭하거나 ID가있는 div가 될 수 있습니다. 특정 콘텐츠는 간단한 모달 대화 상자 창에 자동으로 표시됩니다.간단한 모달 JSON Jquery

JSON 파일

{ 
    "mycontent": [ 
     { 
      "content": "content 1" 
     }, { 
      "entry": "content 2" 
     } 
     , { 
      "entry": "content 3" 
     } 
    ] 
} 

자바 스크립트

jQuery(function ($) { 
    $.getJSON('/json.json', function(data){ 

    // Load dialog on page load 
    //$('#basic-modal-content').modal(); 

    // Load dialog on click 
    $('#basic-modal .basic').click(function (e) { 
     $('#basic-modal-content').modal(); 

     return false; 
    }); 
}); 

HTML

<a href='#' class='basic'>content 1</a> 
<a href='#' class='basic'>content 2</a> 
<a href='#' class='basic'>content 3</a> 
<div id="basic-modal-content" style="display:none;"></div> 

내가 사용 : http://www.ericmmartin.com/projects/simplemodal-demos/이 코드에서

+0

어떤 부분에 붙어 있습니까? JSON? – Blender

+0

기본적으로 작동하도록, 자바 스크립트 부분, 너무 확실하지 않은 방법으로 ID가 동적이되도록 –

+0

모든 도움말 블렌더? –

답변

1

보기 :

$('#basic-modal .basic').click(function (e) { 
    $.getJSON('/json.json', function(data){ 
     if(data != undefined && data.length > 0) 
     { 
      for(i=0; i < data.length; i++) 
      { 
       $('#DIV-ID').append(data.i.content... .... .. you code here...); 
      } 
      $('#basic-modal-content').modal(); 
     } 
    }); 
    return false; 
});