我想在选择框中选择默认选项。
我尝试了很多解决方案,但没有成功。
我想选择processTaskActor值来选择下拉列表。
以下是我的代码
<div>
<select data-bind="options: processChannels,
optionsText: 'propertyText',
optionsValue: $data,
value: processTaskActor,
valueUpdate: 'input' ">
</select>
<div data-bind="with:processTaskActor">
<div data-bind="text: propertyText">
</div>
</div>
<script>
var ViewModel = function(first, last) {
self.processChannels = [
{
"propertyName": "Initiator",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Initiator"
},
{
"propertyName": "Initiator",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Initiator Reject pruchase"
},
{
"propertyName": "Initiator",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Initiator Purchase Approved"
},
{
"propertyName": "Initiator",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Initiator Purchase approved high amount"
},
{
"propertyName": "Manager",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Manager Approval"
},
{
"propertyName": "Finance manager",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Finance manager Approve High amount"
}
];
self.processTaskActor = ko.observable({
"propertyName": "Finance manager",
"propertyType": "User",
"propertyValue": "",
"propertyText": "Finance manager Approve High amount"
});
};
ko.applyBindings(new ViewModel());
</script>
我没有多少使用淘汰赛。
请帮我解决问题。
抱歉英语不好
答案 0 :(得分:1)
试试这个:self.processTaskActor = ko.observable(self.processChannels[5]);
答案 1 :(得分:0)
首先,您需要使processTaskActor成为可观察的,并且processChannel成为observableArray。
self.processTaskActor = ko.observable();
self.processChannels = ko.observableArray...
然后,您可以在可观察数组中搜索所需的确切对象。在创建具有相同值的新对象之前。
var processTaskActor = ko.utils.arrayFirst(self.processChannels(), function (process) {
return process.propertyName === "Finance manager" &&
process.propertyText === "Finance manager Approve High amount";
});
self.processTaskActor(processTaskActor);
请参阅此fiddle: