css – “未绑定”SELECT元素的选项元素的Knockout条件样式
作者:互联网
2026-04-08
我页面上的各种输入都通过敲除绑定到视图模型,比方说客户记录.这一切都很好.
现在,我想在页面顶部放置一个SELECT,其中包含所有客户的列表.用户将选择一个客户,该记录将从数据库中获取,并且数据将绑定到视图模型.
我的问题涉及SELECT列表中项目的条件样式.它将绑定到一组客户对象. Customer对象定义有一个名为hasExpired的函数:
var Customer = function (id, name, expiryDate) { this.id = id; this.customerName = name; this.expiryDate = expiryDate; this.hasExpired = function() { return this.expiryDate == null ? false : true; }; }; ViewModel,页面上的输入绑定到的ViewModel如下所示:
function ViewModel() { var self=this; self.customerRegion = ko.observable(), self.customerName = ko.observable(), . . . self.allCustomers = Customers, // Customers is an array of Customer objects self.selectedCustomer = ko.observable() } 这个淘汰赛绑定工作; SELECT正确填充了客户列表:
过期的css类定义为:
.expired { text-decoration: line-through;} Fiddle
相关推荐
