2015-06-24 9 views
5

मेरा ऐप एक फ़ोल्डर में लग रही है और फिर एक लटकती मेनू में इसके अंदर सभी फ़ोल्डर और html फ़ाइल दिखाने के लिए, और एक iframe के भीतर किसी भी html फ़ाइलें प्रदर्शित करते हैं। मैं एक फ़ाइल "highlighted.html" जो मैं लटकती मेनू में दिखाने के लिए नहीं करना चाहते हैं कहा जाता है, लेकिन अगर यह मौजूदा निर्देशिका में है मैं एक iframe में स्वचालित रूप से यह दिखाने के लिए चाहते हैं।जावास्क्रिप्ट के साथ फ़ाइल कैसे खोजें?

  • पहले समारोह एक ड्रॉपडाउन बॉक्स लोड हो रहा है गतिशील बनाने फ़ोल्डर्स या फ़ाइलें (एचटीएमएल विस्तार के साथ):

    यह वही फ़ोल्डर में है दिखाने के लिए मेरी कोड है।

  • दूसरा समारोह में: अगर एक मौजूदा सबफ़ोल्डर पर क्लिक करें, फिर उस फ़ोल्डर को खोलने और html फ़ाइल (रों) एक iframe में इसे खोलने के लिए के लिए अंदर देखो

    function rendSelects($currentSelectItem, strPath) { 
        var currentSelectLevel = (null === $currentSelectItem ? -1 : parseInt($currentSelectItem.attr('data-selector-level'))), 
        nextOneSelectorHtml = 
         '<select ' + 
         'class="dropdown selectpicker" ' + 
         'name="dd" ' + 
         'data-selector-level="' + (currentSelectLevel + 1) + '" ' + 
         'data-path="' + strPath + '" ' + 
         'onchange="onFsSelectChange(this)"' + 
         '><option text selected> -- select an option -- </option>'; 
    
        $('div.selectors-container select.dropdown').each(function (i, el) { 
         if (parseInt(el.getAttribute('data-selector-level')) > currentSelectLevel) { 
          el.parentNode.removeChild(el); 
          $(el).selectpicker('destroy'); 
         } 
        }); 
    
        if (fsStructure[strPath].subfolders.length > 0) { 
         for (var i = 0; i < fsStructure[strPath].subfolders.length; i++) { 
          nextOneSelectorHtml += 
           '<option ' + 
           'class="subfolder-option" ' + 
           'data-subfolder="' + fsStructure[strPath].subfolders[i] + '" >' + fsStructure[strPath].subfolders[i] + 
          '</option>'; 
         } 
        } 
    
        if (fsStructure[strPath].subshtmls.length > 0) { 
         for (var i = 0; i < fsStructure[strPath].subshtmls.length; i++) { 
          nextOneSelectorHtml += 
           '<option ' + 
           'class="html-page-option" ' + 
           'data-html-page-name="' + fsStructure[strPath].subshtmls[i] + '">' + fsStructure[strPath].subshtmls[i] + 
           '</option>'; 
         } 
        } 
    
        nextOneSelectorHtml += '</select>'; 
        $('div.selectors-container').append(nextOneSelectorHtml); 
        $('div.selectors-container').trigger('dropdownadded.mh'); 
    } 
    
    function onFsSelectChange(el) { 
        var currentSelectorPath = el.getAttribute('data-path'), 
         selectedOption = el.options[el.selectedIndex]; 
    
        if (selectedOption.classList.contains('subfolder-option')) { 
         loadFolderStructure(currentSelectorPath + '/' + selectedOption.getAttribute('data-subfolder'), $(el)) 
        } 
    
        if (selectedOption.classList.contains('html-page-option')) { 
         playSwf(currentSelectorPath + '/' + selectedOption.getAttribute('data-html-page-name')); 
        }  
    } 
    

मैं एक काम प्रदान की है http://tdhtestserver.herobo.com/ पर डेमो।

खैर

उत्तर

0

मैं अपने प्रश्न पर जवाब क्योंकि आप में से कुछ ने मेरी समस्या से नहीं समझा गया है या वे इसे कैसे करना पता नहीं है। तो मैंने पाया कि इतना आसान था और मैंने जो कुछ किया है वह केवल कोड की एक पंक्ति थी।

high(currentSelectorPath + '/'+selectedOption.getAttribute('data-subfolder')+'/highlighted.html'); 

इस लाइन सब कुछ है, जहां high एक नया आइफ्रेम

function onFsSelectChange(el) { 
    var 
    currentSelectorPath = el.getAttribute('data-path'), 
    selectedOption = el.options[el.selectedIndex]; 

    if (selectedOption.classList.contains('subfolder-option')) { 
    loadFolderStructure(currentSelectorPath + '/' + selectedOption.getAttribute('data-subfolder'), $(el)) 
    high(currentSelectorPath + '/'+selectedOption.getAttribute('data-subfolder')+'/highlighted.html'); 
    } 
    if (selectedOption.classList.contains('html-page-option')) { 
    playSwf(currentSelectorPath + '/' + selectedOption.getAttribute('data-html-page-name')); 
    } 

} 
0

हल किया। यदि lighted.html फ़ोल्डर में मौजूद है, तो कोई भी चयन संविधान नहीं है। के src = highlighted.html IIUC साथ एक iFrame प्रदर्शित करते हैं। क्या मैं ठीक हूँ ?

पहला फ़ंक्शन एक ड्रॉपडाउन बॉक्स बनाता है जहां यह गतिशील रूप से फ़ोल्डर या HTML एक्सटेंशन के साथ फ़ाइलों को लोड करता है। ठीक है, तो चलिए जांचें कि हाइलाइट किया गया है या नहीं।

 function rendSelects($currentSelectItem, strPath) { 
//here : (begin of change)    
if(strPath.indexOf("hightlighted")>=0) { 
         $("#myiFrame").attr('src', /path/to/highlighted) 
       } 

    // enfd of change. The continue as : 
    var currentSelectLevel = (null === $currentSelectItem ? -1 : parseInt($currentSelectItem.attr('data-selector-level'))), 
     nextOneSelectorHtml =.... 
+0

आप यह नहीं कह सकते हैं '$ (" # myiFrame ") है बदल गया था।attr ('src',/path/to/highlighted) 'क्योंकि पथ गतिशील रूप से' fsStructure [strPath] .subshtmls [i] ' –

+0

@ मार्कसहेनर: कोई जांच नहीं है। $ ("# MyiFrame") कहें। बाद में attr ('src',/path/to/highlighted)। असल में, मामला चुनना है: 1. $ (myframeid) .attr (src ...) और 2. कृपया मेरा एक और जवाब देखें – 3pic

0

वास्तव में, इस मामले के बीच चयन करने के लिए है:। 1. $ (myframeid) .attr (src ...) और 2. $ ('div.selectors-कंटेनर') संलग्न (nextOneSelectorHtml) ; /// आपको हाइलाइट किए गए या नहीं ढूंढने के आधार पर 1 या 2 "प्रस्तुत करना" है।

function rendSelects($currentSelectItem, strPath) { 
//1of3 // let's add a boolean 
var is_highlighted_here = false; 
var highlighted_path=""; 
//done. 

    var currentSelectLevel = (null === $currentSelectItem ? -1 : parseInt($currentSelectItem.attr('data-selector-level'))), 
    nextOneSelectorHtml = 
     '<select ' + 
     'class="dropdown selectpicker" ' + 
     'name="dd" ' + 
     'data-selector-level="' + (currentSelectLevel + 1) + '" ' + 
     'data-path="' + strPath + '" ' + 
     'onchange="onFsSelectChange(this)"' + 
     '><option text selected> -- select an option -- </option>'; 

    $('div.selectors-container select.dropdown').each(function (i, el) { 
     if (parseInt(el.getAttribute('data-selector-level')) > currentSelectLevel) { 
      el.parentNode.removeChild(el); 
      $(el).selectpicker('destroy'); 
     } 
    }); 

    if (fsStructure[strPath].subfolders.length > 0) { 
     for (var i = 0; i < fsStructure[strPath].subfolders.length; i++) { 
      nextOneSelectorHtml += 
       '<option ' + 
       'class="subfolder-option" ' + 
       'data-subfolder="' + fsStructure[strPath].subfolders[i] + '" >' + fsStructure[strPath].subfolders[i] + 
      '</option>'; 
     } 
    } 

    if (fsStructure[strPath].subshtmls.length > 0) { 
     for (var i = 0; i < fsStructure[strPath].subshtmls.length; i++) { 

// 2of3 // oh !! look at here : 
if(fsStructure[strPath].subshtmls[i].indexOf("highlighted")>=0) 
{ 
s_highlighted_here=true; 
highlighted_path = fsStructure[strPath].subshtmls[i]; 
} 
//done. scroll to bottom. 


      nextOneSelectorHtml += 
       '<option ' + 
       'class="html-page-option" ' + 
       'data-html-page-name="' + fsStructure[strPath].subshtmls[i] + '">' + fsStructure[strPath].subshtmls[i] + 
       '</option>'; 
     } 
    } 

    nextOneSelectorHtml += '</select>'; 
// 3of3 // here finally 
    if(is_highlighted_here) { 
         $("#myiFrame").attr('src', highlighted_path); 
    } 
    else { 
    $('div.selectors-container').append(nextOneSelectorHtml); 
    $('div.selectors-container').trigger('dropdownadded.mh'); 
    } 

}//function end 

ठीक है, अगर मैं केवल बदल प्रदर्शन: - बहुत समारोह शुरू में:

//1of3 
    var is_highlighted_here = false; 
    var highlighted_path=""; 
  • जब फ़ोल्डर struct पार्स करने:

    // 2of3 // oh !! look at here : if(fsStructure[strPath].subshtmls[i].indexOf("highlighted")>=0) { s_highlighted_here=true; highlighted_path = fsStructure[strPath].subshtmls[i]; }

  • और अंत में, जब प्रतिपादन:

    // 3of3 if(is_highlighted_here) { $("#myiFrame").attr('src', highlighted_path); } else { $('div.selectors-container').append(nextOneSelectorHtml); $('div.selectors-container').trigger('dropdownadded.mh'); }

+0

यह बिल्कुल वही काम कर रहा है जैसा कि पहले कोई बदलाव नहीं है। आप बस वही फाइलें कॉल करते हैं। मुझे एक निर्दिष्ट फाइल कॉल करने की जरूरत है। –

+0

ठीक है पूर्ण स्रोत @MarkusHayner के साथ एक लिंक प्रदान करें। आपकी मदद करने के लिए ठीक है, हालांकि ज्यादा समय नहीं है। स्रोत प्रदान करें। नोट: आपके आईफ्रेम को रीफ्रेश की आवश्यकता हो सकती है। – 3pic

संबंधित मुद्दे