Populating Control With Knockout.Js From Array

Last Reply 7 days ago By pandeyism

Posted 7 days ago

 I have a data-binding question with knockout.js. I have an array that is populated correctly. I am just trying to display the data from my array into a control on my page. I’ve tried a bunch of different ways to try to get this to display .ajax() different functions. Setting it up multiple ways with ‘ko.observableArray([]);’ and some other ways to but… no luck. Then I will grab the value of the selected item probably with indexOf but I cant get my control to display my data. Here is my code that I am currently using.


// View
<div class="col-sm-2 @assignmentClass"><label for="lstCategory">Category</label></div>
                <div class="col-sm-2 @assignmentClass">
                    <select data-bind="options: category,
                                       optionsText: 'label',
                                       optionsValue: 'PKValue',
                                       value: webimage_id" 
                            id="lstCategory" class="form-control"></select>
// part of my viewmodel
var AssignmentViewModel = function() {
        var self = this;
        self.employe_id = ko.observable(loginemployee_id);        
        self.availableTechs = ko.observableArray([new PickListItem("", "", loginemployee_id)]);

        self.webimage_id = ko.observable(0);//store the webimage_id
        self.webimagearray = [];
            //self.category = ko.observableArray([new PickListItem("","",)]);
        self.category = ko.observableArray([]);
        //self.specifics = ko.observableArray([]);
        self.wis_id = ko.observable(0);//store the wis_id
// populating my list for the viewmodel
if (woimageindex >= 0)
                            var categories = arrWOWebRequestImagesList[woimageindex].list;
                            var list = [];

                            // added new PickListModel(webimage_id, after .push(
                                //list.push(new PickListModel(webimage_id, $.map(arrWOWebRequestImagesList[woimageindex].list, function (item) {
                            list.push( $.map(arrWOWebRequestImagesList[woimageindex].list, function (item) {
                                return new PickListItem(item.caption, item.caption, item.webimage_id);

                            //url = rootPath + "utility/GetEngineer";
                            //    type: 'GET',
                            //    url: url,
                            //    data: { text: '' },
                            //    success: function (data) {
                            //        list.push(new PickListModel(corp_id, $.map(data, function (item) {
                            //            return new PickListItem((item.displaylabel === "" ? item.label : item.displaylabel), item.label, item.value);
                            //        })));
                            //        vmAssignment.category(list);
                            //    },
                            //    dataType: 'json'

                            //vmAssignment.specifics(arrWOWebRequestImagesList[woimageindex].list where webimage_id=0);


You are viewing reply posted by: pandeyism 7 days ago.