Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    come chiamare una funzione da click

    Dopo aver definito il seguente bottone:

    <input id="search_ontology_button" name="search_ontology_button" type="button" value="Ricerca" class="ui-state-default ui-corner-all">

    scrivo: JQ('#search_ontology_button').click(???????);

    Il mio obbiettivo e' chiamare una funzione che esegue la ricerca di una stringa dentro un albero.
    Dal sito jstree ho scaricato l'ultima versione che include la ricerca e il codice e' il seguente:

    /*
    * jsTree search plugin 1.0
    * Enables both sync and async search on the tree
    * DOES NOT WORK WITH JSON PROGRESSIVE RENDER
    */
    (function ($) {
    $.expr[':'].jstree_contains = function(a,i,m){
    return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
    };
    $.jstree.plugin("search", {
    __init : function () {
    this.data.search.str = "";
    this.data.search.result = $();
    },
    defaults : {
    ajax : false, // OR ajax object
    case_insensitive : false
    },
    _fn : {
    search : function (str, skip_async) {
    if(str === "") { return; }
    var s = this.get_settings().search,
    t = this,
    error_func = function () { },
    success_func = function () { };
    this.data.search.str = str;

    if(!skip_async && s.ajax !== false && this.get_container().find(".jstree-closed:eq(0)").length > 0) {
    this.search.supress_callback = true;
    error_func = function () { };
    success_func = function (d, t, x) {
    var sf = this.get_settings().search.ajax.success;
    if(sf) { d = sf.call(this,d,t,x) || d; }
    this.data.search.to_open = d;
    this._search_open();
    };
    s.ajax.context = this;
    s.ajax.error = error_func;
    s.ajax.success = success_func;
    if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, str); }
    if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, str); }
    if(!s.ajax.data) { s.ajax.data = { "search_string" : str }; }
    if(!s.ajax.dataType || /^json/.exec(s.ajax.dataType)) { s.ajax.dataType = "json"; }
    $.ajax(s.ajax);
    return;
    }
    if(this.data.search.result.length) { this.clear_search(); }
    this.data.search.result = this.get_container().find("a" + (this.data.languages ? "." + this.get_lang() : "" ) + ":" + (s.case_insensitive ? "jstree_contains" : "contains") + "(" + this.data.search.str + ")");
    this.data.search.result.addClass("jstree-search").parents(".jstree-closed").each(function () {
    t.open_node(this, false, true);
    });
    this.__callback({ nodes : this.data.search.result, str : str });
    },
    clear_search : function (str) {
    this.data.search.result.removeClass("jstree-search");
    this.__callback(this.data.search.result);
    this.data.search.result = $();
    },
    _search_open : function (is_callback) {
    var _this = this,
    done = true,
    current = [],
    remaining = [];
    if(this.data.search.to_open.length) {
    $.each(this.data.search.to_open, function (i, val) {
    if(val == "#") { return true; }
    if($(val).length && $(val).is(".jstree-closed")) { current.push(val); }
    else { remaining.push(val); }
    });
    if(current.length) {
    this.data.search.to_open = remaining;
    $.each(current, function (i, val) {
    _this.open_node(val, function () { _this._search_open(true); });
    });
    done = false;
    }
    }
    if(done) { this.search(this.data.search.str, true); }
    }
    }
    });
    })(jQuery);


    al posto di "?????" cosa devo scrivere?? e tale codice??

  2. #2
    Utente di HTML.it L'avatar di m4rko80
    Registrato dal
    Aug 2008
    residenza
    Milano
    Messaggi
    2,654
    $(document).ready(function{

    $('#id').bind('click', function(){
    tuaFunzione();
    });


    });

  3. #3
    forse mi son spiegato male,la mia funzione di ricerca non la volevo riscrivere dato che il jstree la supporta gia.e il codice della ricerca l'ho postato!non so dove devo inserirlo pero' e come chiamarlo!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.