문제

I'm trying to implement a live search on my photos site using jQuery and the autocomplete plugin. Everything works when I specifiy the data locally:

var data = [ {text:'Link A', url:'/page1'}, {text:'Link B', url: '/page2'} ];

However when I move this to PHP, jQuery is unable to parse the results properly. I'm really not sure what's going on here. My current code is below:

<script>
$(document).ready(function(){
var data = '/livesearch'; 
$("#aut_field").autocomplete(data, {
  formatItem: function(item) {
    return item.text;
  }
}).result(function(event, item) {
  location.href = item.url;
});
                });
</script>

And my PHP script prints a multidimensional array in the following format:

{"1":{"text":"Google Website","url":"http:\/\/www.google.com"},
 "2":{"text":"Yahoo Website","url":"http:\/\/yahoo.com"},}

However when I do alert(item.text) the variable says undefined.

If I do alert(item) I see the entire string as outputted by PHP.

I tried playing around with eval() but I'm not sure where to put it or how to get JS to actually interpret the data. Thanks for your help. Sample code specific to my implementation is appreciated.

도움이 되었습니까?

해결책

이미 설명했듯이보기는 목록의 모든 작업 (> 5000 항목)을 쿼리하고 페이지 매김이있는 모든 항목 (> 5000)을 모두 반환합니다.WebPart가 작동하려면 5000 개 미만의 항목을 쿼리해야하며 5000 개 미만의 항목도 반환해야합니다.필터링 열도 인덱싱해야합니다.

현실적으로 말하면, 옵션에는 다음이 포함됩니다.

  1. 현재 사용자에게 할당 된 작업을 표시하려는 경우, '[me]와 동일한 필터가 할당 된 필터를 만들고 할당 된 열 인덱스로 뷰를 만듭니다.
  2. 모든 사용자에 대한 작업을 표시하려면 불완전한 작업을 표시하는 것이 좋습니다./ li>

다른 팁

try in your php this pattern:

[
   {"text":"Google Website","url":"http:\/\/www.google.com"},
   {"text":"Yahoo Website","url":"http:\/\/yahoo.com"}
]

And your PHP script return a multidimensional array/object mix. If you insist (you blow up your var with several "text:" amd "url;") it shou1ld be:

[[{"text":"Google Website","url":"http:\/\/www.google.com"}],[{"text":"Yahoo Website","url":"http:\/\/yahoo.com"}]]

Better:

var x=[["Google Website","http:\/\/www.google.com"],["Yahoo Website","http:\/\/yahoo.com"]];

If you want to jump to Yahoo Website: var url=x[1][1];

Or:

var x={"Google_Website":"http:\/\/www.google.com","Yahoo_Website":"http:\/\/yahoo.com"};

If you want to jump to Google_Website: var url=x["Google_Website"];

My tip: visit enter link description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top