Possible Duplicate:
Autocomplete combobox with Knockout JS template / JQuery
We're working on a MVC/MVVM/JQuery/Knockout project. So the client is mostly disconnected and all the data is initialized by the controller and serialized into our client side viewmodel. I'm having problems with autocompletes and have created a custom jquery autocomplete that works, but i need to make is easier to implement. We were using jqAuto but once we removed our stubbed in data and started receiving it from the server I could not get it to work...I tried and tried and tried more...just would not work.
So here is what I have...and it works.
<input id="DiagramNumberInput" />
<input id="DiagramNumberSelectionID" data-bind="value:viewModel.SelectedValue"/>
$('#DiagramNumberInput').autocomplete({
source: $.map(viewModel.InitializationValues.ListsOptions.AvailableDiagramNumbersArray(), function (item) {
return {
lable: item.Name(),
value: item.Name(),
id: item.ID()
};
}),
minLength: 1,
select: function (event, ui) {
$('#DiagramNumberSelectionID').val(ui.item.id);
}
});
As I said, I have many autocompletes and I need to encapsulate this function and would also like it to work so I don't have to use a separate html input for the selected ID binding.
Here is what I'm looking for
<input id="DiagramNumberInput" data-bind="value: myfunction(myarray, viewModel.SelectedDiagNumberID)/>