jquery-flexdatalist icon indicating copy to clipboard operation
jquery-flexdatalist copied to clipboard

How can I get current property of each data in visbleProperties for custom template

Open ali-ehmed opened this issue 6 years ago • 0 comments

I'm creating a custom template with the JSON data from server. I know that when any thing passed to visibleProperties, flexdatalist parses the string "{name, desc}" and add in the "li". But I have to make a conditional template based on the data I have. For example below template variable has a custom template I want to make, but when I actually make a condition like "type == 'Games'", it gives an error that "type" is not defined. So I am assuming that if I can get a passed data/this/item variable from the plugin in which I can have a data then it may solve the problem and I can use something like.

`${ item.type === "Games" } ? ...`

The chunk I am using:

 var template = `
          <div class="row">
            <div class="col-md-3">
              <img src="{thumb}" class="img-fluid rounded" alt=''>
            </div>
            <div class="pl-0 col-md-9">
              <h5 class="name">{name}</h5>
              ${
                type == 'Games' ?
                  `
                    <p class="details">
                      <span class="release-date mr-1"><strong>Release Date:</strong> {first_release_date}</span>
                      <span class="rating"><i class="fa fa-star"></i> {rating} </span>
                    </p>
                  `
                  :
                  `
                    <p class="details mt-1">
                      <span class="in-sell"><strong class="text-success">Selling</strong> 7984</span>
                      <span class="in-exchange"><strong class="text-primary">Exchange</strong> 7984 </span>
                    </p>
                  `
              }
            </div>
          </div>
`;
$('.flexdatalist').flexdatalist({
    minLength: 1,
    searchIn: 'name',
    url: '/search',
    requestType: 'POST',
    requestContentType: 'json',
    visibleProperties: template,
    groupBy: 'type'
  });

ali-ehmed avatar Jan 20 '19 11:01 ali-ehmed