Вопрос

Is it possible to use like fuse.js with an XML document instead of JSON? As it is now I only have an XML document with data and hope that I shouldn't make a new version as well for JSON.

Hope someone can help me out which direction I can/should go.

Kind regards, Niels

Это было полезно?

Решение

Found the solution myself. Instead of the example with JSON placed on http://kiro.me/projects/fuse.html, here is the version with an XML call instead :)

$(function() {

function start(books) {
var $inputSearch = $('#hero-search'),
    $results = $('#results ul'),
    $authorCheckbox = $('#value'),
    $titleCheckbox = $('#typeId'),
    $caseCheckbox = $('#case'),

    searchAuthors = true,
    searchTitles = false,
    isCaseSensitive = false,

    fuse;

function search() {

  $results.empty();
  $.each(r, function(i, val) {
        $resultShops.append('<li class="result-item"><a href="' + this.url + '" target="_blank"><span><img src="' + this.statusId + '" /></span> ' + this.value + '</a></li>');
  });
}

function createFuse() {
  var keys = [];
  if (searchAuthors) {
    keys.push('value');
  }
  if (searchTitles) {
    keys.push('typeId');
  }
  fuse = new Fuse(books, {
    keys: keys,
    caseSensitive: isCaseSensitive
  });
}

$inputSearch.on('keyup', search);

createFuse();
}



$.ajax({
type: 'GET',
dataType: 'xml',
url: 'xml-document/document.xml',
success: function(response) {
    var suggestions = [];                   
    $(response).find("searchResults").children().each(function(i, elm) {                            
        var name = $(elm).find('name').text();
        var url = $(elm).find('url').text();
        var description = $(elm).find('description').text();
        var statusId = $(elm).find('status').text();
        var typeId = $(elm).find('type').text();

        var result = {};
        result.value = name;
        result.url = url;
        result.description = description;
        result.statusId = statusId;
        result.typeId = typeId;

        suggestions.push(result);
    });
    start(suggestions);
},
error: function(response) {
    console.log('failure',response);
}
});
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top