html - How could *data inter-dependent* <select> dropdowns in rails be populated quickly? -


users need select car.
have several dropdowns when picking car in order pick year, make, model , submodel. don't know use select options make/model/submodel interdependent.
once pick year use ajax make requests query activerecord populate make dropdown.
when pick make use ajax query , populate model dropdown. when pick model ajax query , populate submodel dropdown.

the problem lot of separate network requests , in real-world conditions of low bandwidth, network issues, etc. quite there pauses severely impacting user experience , leading failures.

what approaches avoid these network requests. in there approach store of several thousand makes-model combinations on client browser?

currently data stored in sql database accessed via activerecord in rails framework. each dropdown selection results in query because yuou can't show populate , show make until know year , can't populate , show model until know make. same submodel (though i've omitted submodel rest of post simplicity!).

would session (http://simonsmith.io/speeding-things-up-with-sessionstorage/) storage of json data 10,000 combinations possible? see sessionstorage can relied on have @ least 5mb(5,200,000 bytes) gives me 5200000/10000= 520 bytes per record. enough? if persists session , across pages in many cases kick off on previous page , if had time finish wouldn't need external call @ on relevant (next) page. need refresh data either or on demand new year-make-models added periodically (several times year).

ultimately think solution here useful large number of applications , companies. example here of picking vehicle used dozens of major car insurance websites (who multiple calls right now). general appraoch of storing client side data relatioship dependent sdropdown mapply in many other situations such online shopping make-brand-year-model. backend framework populate sessionstorage done via different backend frameworks.

another options might try google's lovefield - https://github.com/google/lovefield more @ https://www.youtube.com/watch?v=s1auiq8ga1k it's open source , works in ff, chrome, ie, safari, etc.

seems sessionstorage might better our (considerable) business basing on google 100 day dev thing - though open source.

hello can create json object detail , based on value selected can loop array , populate value. let me

var cardetail = [{    "name": "maruti",    "model": [{      "name": "swift",      "year": ["2005", "2006", "2008"]    }, {      "name": "alto",      "year": ["2009", "2010", "2011"]    }]  }, {    "name": "hundai",    "model": [{      "name": "i20",      "year": ["2011", "2012", "2013"]    }, {      "name": "i20",      "year": ["2013", "2014", "2015"]    }]  }];    var currentcumpany = null;  var currentmodel = null;  $(document).ready(function() {   $("#company").append("<option value=''>select company</option>");    (i = 0; < cardetail.length; i++) {      $("#company").append("<option value='" + cardetail[i].name + "'>" + cardetail[i].name + "</option>");    };      $("#company").change(function() {        (i = 0; < cardetail.length; i++) {        if (cardetail[i].name == $("#company").val()) {          currentcumpany = cardetail[i];        }      };       $("#model").html("");      (i = 0; < currentcumpany.model.length; i++) {        $("#model").append("<option value='" + currentcumpany.model[i].name + "'>" + currentcumpany.model[i].name + "</option>");      };    });     $("#company").change(function() {        (i = 0; < cardetail.length; i++) {        if (cardetail[i].name == $("#company").val()) {          currentcumpany = cardetail[i];        }      };       $("#model").html("");      (i = 0; < currentcumpany.model.length; i++) {        $("#model").append("<option value='" + currentcumpany.model[i].name + "'>" + currentcumpany.model[i].name + "</option>");      };    });           $("#model").change(function() {                     (i = 0; < currentcumpany.model.length; i++) {                if (currentcumpany.model[i].name == $("#model").val()) {          currentmodel = currentcumpany.model[i];        }              };                     $("#year").html("");             (i = 0; < currentmodel.year.length; i++) {        $("#year").append("<option value='" + currentmodel.year[i] + "'>" + currentmodel.year[i] + "</option>");      };    });            });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <select id="company"></select>  <select id="model"></select>  <select id="year"></select>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -