How to get the objects of the selected ITem

Posted by Vuyiswamb under HTML 5 on 7/12/2012 | Points: 10 | Views : 956 | Status : [Member] [MVP] [Administrator] | Replies : 0
Good day

i am new to knockout ,

I am bringing back the data from a control and i am doing the autocomplete and i show the results in a listbox as depicted below


$(function () {
$("#txtSearchString").keyup(function () {
$("#lstSearchOptions").hide('fast');


if ($("#txtSearchString").val().length >= 3)
{
var data = {}
data.searchString = $("#txtSearchString").val();
$.getJSON("/SearchCars/SearchCars", data, function (result) {
//Autocomplete binding
var viewModel =
{

SearchOptions: ko.observableArray(result), // These are the initial options

}
//item.Model + ' ' + item.Type + ' ' + item.Year
ko.applyBindings(viewModel,document.getElementById("stSearchOptions"));
ko.applyBindings(viewModel, document.getElementById("selectedcarid"));
if (result != null)
{
$("#lstSearchOptions").show('fast');
}
});
}
});
});


now when the user select something i need to get the selected ID and i also want the Year and this is my HTML


   <select id="lstSearchOptions" data-bind="options: SearchOptions, optionsText: function(item) {
return item.Model + ' ' + item.Type + ' ' + item.Year}, optionsValue: 'CarId'"
multiple="multiple" size="-1" class="searchOptions">
</select>


and i have this to assign the value

$(function () {
$("#lstSearchOptions").change(function () {
$("#selectedcarid").val($("#lstSearchOptions option:selected").val());

});

$("#lstSearchOptions").blur(function () {
$("#lstSearchOptions").hide("fast");


});
});


so i can get the ID from here

$("#selectedcarid").val($("#lstSearchOptions option:selected").val());


but have a Problem to getting the year

Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

(No response found.)

Login to post response