问题描述
我正在使用淘汰赛,我有一个HTML页面,我想在其中检查某些值的字符串.就像我有一个字符串'A:B:C:D:F:G:H:I',我只想用剔除检查html中的此字符串.型号
I am using knockout and i have one html page where i want to check string with some value.Like i have one string 'A:B:C:D:F:G:H:I', i just want to check this string in html with knockout if.Model
var viewModel = function () {
var self = this;
self.key = ko.observable("A:B:C:D:F:G:H:I");
}
查看
<!-- ko if: key().contains('A') -->
<input type="checkbox" checked="checked" value="A"/>
<!-- /ko -->
<!-- ko if: key().contains('B') -->
<input type="checkbox" checked="checked" value="B"/>
<!-- /ko -->
在此可以说key是一个字符串,我想检查key是否包含A然后执行一些操作,如果B然后执行其他操作.如何通过淘汰赛实现这一目标.
In this lets say key is a string , i want to check if key contain A then do some, if B then do some other thing. How to achieve it with knockout.
推荐答案
我刚刚看到了这个问题.甚至我也遇到同样的问题.我找到了一种解决方案,它可能会对某人有所帮助.
I just saw this question. Even I was stuck with same problem. I have found a solution, It may help someone.
var viewModel = function () {
var self = this;
self.key = ko.observable("A:B:C:D:F:G:H:I");
}
所以在您看来,您可以执行以下操作
So in your view you can do something like this
<!-- ko if: key().indexOf('A') > -1 -->
<input type="checkbox" checked="checked" value="A"/>
<!-- /ko -->
<!-- ko if: key().indexOf('B') > -1 -->
<input type="checkbox" checked="checked" value="B"/>
<!-- /ko -->
这篇关于如何检查击倒中的含量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!