| Page 1 of 1 | [ 3 posts ] |
|
I have a DataSource which contains duplicate revised values like;
Code: {"ResultSet":{ "Result":[ {"original":"5MAIL.COM","revised":"GMAIL.COM"}, {"original":"8MAIL.COM","revised":"GMAIL.COM"}, {"original":"A0L.COM","revised":"AOL.COM"}, {"original":"AAOL.COM","revised":"AOL.COM"} ... I'm using it in a DataTable AND AutoComplete widget Code: Y.one('#revised').plug(Y.Plugin.AutoComplete, { requestTemplate: '', resultTextLocator: 'revised', resultFilters: 'startsWith', resultHighlighter: 'startsWith', source: dataSource }); However, there are duplicate results in the dropdown, what/where is the best way to only select DISTINCT revised values from the oDS? |
|
This might not be a drop-in solution, but you can use the Y.Array utilities to take an array (ResultSet.Result) and pluck out all of 'revised' values and then pass that through the Y.Array.dedupe method to generate an unique array.
Code: YUI().use('collection', function(Y) { var src = { "ResultSet": { "Result": [{ "original": "5MAIL.COM", "revised": "GMAIL.COM" }, { "original": "8MAIL.COM", "revised": "GMAIL.COM" }, { "original": "A0L.COM", "revised": "AOL.COM" }, { "original": "AAOL.COM", "revised": "AOL.COM" }] } }; var results = Y.Array(src.ResultSet.Result); var allResult = results.map(function(item) { return item.revised; }); var uniqResults = Y.Array.dedupe(allResult); Y.log(uniqResults); }); |
|
Patrick,
Recommend you look into the Custom resultFilter for Autocomplete, specifically AutoComplete User Guide - Writing Results Filters. You would define a function to filter the results, and could incorporate sjungling's approach or your own very easily. Todd |
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group