0 Replies - 425 Views - Last Post: 14 May 2019 - 09:32 AM

#1 Exceedinglife   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 219
  • Joined: 01-July 12

Populating control with Knockout.js from array

Posted 14 May 2019 - 09:32 AM

Hello everyone,
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>
                </div>
// 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;
                            alert(categories.count);
                            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";
                            //$.ajax({
                            //    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.category(list);
                            //vmAssignment.specifics(arrWOWebRequestImagesList[woimageindex].list where webimage_id=0);
                        }



Is This A Good Question/Topic? 0
  • +

Page 1 of 1