Coder Social home page Coder Social logo

Comments (3)

krzkrzkrz avatar krzkrzkrz commented on August 11, 2024

So far I tried creating a component executes an AJAX call to my endpoint, which returns a response and feeds it into source at $('.ui.search').search. The result box doesn't show any results...

The component object:

import Ember from 'ember';

export default Ember.Component.extend({
  keywordChanged: function() {
    this.set('isSearching', true);
    Ember.run.debounce(this, this.productSearch, 2000);
  }.observes('keyword'),

  productSearch: function() {
    var _this = this;

    Ember.$.ajax({
      url: '/api/v1/searches/products',
      type: 'GET',
      data: {
        name: this.get('keyword')
      },
      success: function(response) {
        // response.searches returns:
        // [
        //   {
        //     name: 'Steel hat',
        //     description: 'Lorem ipsum',
        //   },
        //   {
        //     name: 'Green flower',
        //     description: 'Lorem ipsum dolor',
        //   }
        // ];

        _this.$('.ui.search').search({
          source: response.searches,
          searchFields: ['name'],
          searchFullText: false
        });

        _this.set('isSearching', false);
      },
      error: function(reason) {
        console.log(reason);
      }
    });
  }
});

The component template:

<div {{bind-attr class='isSearching:loading :ui :fluid :search'}}>
  <div class="ui icon input">
    {{input type='text' value=keyword placeholder='Search' class='prompt'}}
    <i class="search icon"></i>
  </div>
  <div class="results"></div>
</div>

from semantic-ui-ember.

aaronbhansen avatar aaronbhansen commented on August 11, 2024

I've looked at doing a search component, but haven't thought of a good way yet to customize it for each persons individual needs. Since the results are so customized based on the search. We might implement a base mixin you can use for search and then you override the specific calls you need to make yours work, but haven't gotten that far yet.

from semantic-ui-ember.

aaronbhansen avatar aaronbhansen commented on August 11, 2024

As a follow up to this, looking at the example above, you should be able to do this all through ember and then just reinitialize the search component if changed. In your example above, you could change it to the following

<div {{bind-attr class='isSearching:loading :ui :fluid :search'}}>
  <div class="ui icon input">
    {{input type='text' value=keyword placeholder='Search' class='prompt'}}
    <i class="search icon"></i>
  </div>
  <div class="results">
  {{#each results as |result|}}
     <a class="result">{{result}}</a>
  {{/each}}
  </div>
</div>

Then after your ajax is completed, you could render the results and call $().search() on the main html again. We'll look at providing a better way to handle this through the component, but going to close this specific issue out for now.

from semantic-ui-ember.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.