我对kickout.js有一个数据绑定问题。我有一个正确填充的数组。我只是想将数组中的数据显示到页面上的控件中。我尝试了多种方法来尝试显示.ajax()不同的函数。使用“ ko.observableArray([]);”和其他一些方法来进行多种设置,但是……不走运。然后,我可能会使用indexOf来获取所选项目的值,但是我无法控制显示我的数据。这是我当前正在使用的代码。
// 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);
}