2012-05-14 3 views
1

그래서 여기에 필요가 있습니다.jQuery 자동 완성. 옵션 목록에서 URL을로드하십시오. 로컬 데이터 세트로 수행

매일 몇 개의 디렉토리를 방문하며 바탕 화면에 바로 가기가 꽉 찼습니다. 나는 이것을 제거하고 싶다. 그래서 나는 내가 입력 할 때 자동으로 완성 될 디렉토리 이름 목록 (이 이름은 로컬 데이터 소스에 있음)을 가진 간단한 웹 페이지를 사용할 생각을하고 그 파일을 클릭하면 열어야한다. 디렉토리. URL을 열어 클릭하는 것과 같습니다. 아이디어를 얻었습니까?

jQuery UI의 코드를 사용했습니다.

<!DOCTYPE html> 
<html lang="en"> 
<head> 

<meta charset="utf-8"> 
<title>jQuery UI Autocomplete - Default functionality</title> 
<link rel="stylesheet" href="css/redmond/jquery-ui-1.8.20.custom.css"> 
<script src="js/jquery-1.7.2.min.js"></script> 
<script src="js/jquery-ui-1.8.20.custom.min.js"></script> 

<link rel="stylesheet" href="../demos.css"> 
<script> 
$(function() { 
var availableTags = [ 
"ActionScript", 
"AppleScript", 
"Asp", 
"BASIC", 
"C", 
"C++", 
"Clojure", 
"COBOL", 
"ColdFusion", 
"Python", 
"Ruby", 
"Scala", 
"Scheme" 
]; 
$("#tags").autocomplete({ 
source: availableTags 
}); 
}); 
</script> 
</head> 
<body> 

<div class="demo"> 
<div class="ui-widget"> 
<label for="tags">Tags: </label> 
<input id="tags" /> 
</div> 

</div><!-- End demo --> 



</body> 
</html> 

미리 감사드립니다.

+0

어떤 언어를 사용합니까? asp.net? PHP? –

답변

0

그 다음 내가이

마크 업처럼했을 것 asp.net의 경우 :

<asp:TextBox runat="server" ID="txtFileS" ></asp:TextBox> 

JQuery와 :

$(document).ready(function() { 
      $('#txtFileS').autocomplete({ 
       source: function(request, response) { 
        $.ajax({ 
        url: "Default.aspx/GetFileList", 
         data: "{ 'query': '" + request.term + "' }", 
         dataType: "json", 
         type: "POST", 
         contentType: "application/json; charset=utf-8", 
         dataFilter: function(data) { return data; }, 
         success: function(data) { 
          response($.map(data.d, function(item) { 
           return { 
            value: item 
           }; 
          })); 
         } 
        }); 
       } 

      }); 
     }); 

서버 측 방법 :

[WebMethod] 
    public static string[] GetFileList(string query) 
    { 
     var s = Directory.GetFiles("C:\\").ToArray(); 
     return s; // you need to filter the array according to the query. 
    } 

PS : 쿼리를 필터링해야합니다. 입력 할 때. 서버 측 코드.

+0

ASP.NET이 없습니다. 기본 HTML 및 jQuery이며 다른 컴퓨터에서도 실행됩니다. 서버와 관련이 없습니다. – williamtell

+0

@williamtell 당신은 자바 스크립트로 할 수 없어, 당신은 소켓, 파일 스트림에 액세스 할 수있는 콘텐츠를 사용해야합니다 http://stackoverflow.com/questions/2924935/list-files-in-a-directory-using-only-javascript –

+0

Open C Dir은 C 디렉토리를 엽니 다. 나는 이들과 같은 몇 개의 링크를 갖고 다른 디렉토리를 열고 싶다. 나는 복잡한 일을하지 않고있다. 많은 단축키를 사용하는 대신 웹 페이지를 사용하고 컴퓨터에서 다른 디렉토리를 열려고합니다. – williamtell