jQuery Autocomplete / Twitter Typeahead Populate Multiple Fields

浪尽此生 提交于 2019-12-08 07:50:57

问题


I'm currently using TypeAhead (Bootstrap) but happy to use jQuery Autocomplete to accomplish what I need

I have 5 input fields. I also have a table structured as below so I'll be using a remote datasource:

Classification   | Model | Cost  | Depreciation  | Warranty
-----------------------------------------------------------
Laptop/PC/Server | X/Y/Z | 1/2/3 | 1/2/3/4/5/6/7 | 1/2/3

So there are multiple values for each column. A laptop can only have certain models attributed to it

Question One

Let's say I choose "Laptop" for an autocomplete field, is there anyway to refine the "Model" field to pick out only those models attributed with the chosen laptop?

Question Two

In the first instance, let's presume the above isn't possible. Let's say I chose "Laptop" from the autocomplete field for "Classification". I then go to the "Model" autocomplete field and choose for example "Latitude D830". Is there anyway I can then populate the Cost/Depreciation/Warranty field automatically?

Let's now say the first question is possible. What's the best way to combine the two? The current TypeAhead initialisation is pretty vanilla

$('#inputClassification').typeahead([
        {
            name: 'classification',
            local: ["Tablet", "PC", "Laptop", "Phone", "Printer", "Switch", "Router", "Firewall", "Wireless AP", "Wireless Controller", "Server", "Storage"]
        }
        ]);

Thanks!


回答1:


Seems something along these lines seems to work

       $('#inputLocationStatus').typeahead({
            name: 'poiuy',
            prefetch: 'js/names.json',
            ttl:0                                                             
        }).on('typeahead:selected', onSelected);

        function onSelected($e, datum) {
            $('#inputDepartment').val(datum['description']);
        }


来源:https://stackoverflow.com/questions/19538591/jquery-autocomplete-twitter-typeahead-populate-multiple-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!