我必须使用Regex在Knockout条件注释中找到一个字符串。场景是,将有两种 KnockoutConditionalStatement ,这将根据用户详细信息付费/未付款而有所不同。
陈述 - 我 - 未付款
<!-- ko if: IsPaidUser() --><!-- /ko -->
<!-- ko if: !IsPaidUser() -->
<!-- ko if: $parent.isEditable($data.UserName, $data.UserRole) -->
<i title="NotPaid" class="fa fa-toggle-on faIcons fa-rotate-180 toggleOff" data bind="click: function (data, event) { $parent.toggleUserAccountStatus($index(), 'reactivate') }"></i>
<!-- /ko -->
<!-- ko if: !$parent.isEditable($data.UserName, $data.UserRole) --><!-- /ko -->
<i style="display: none;">00</i>
<!-- /ko -->
陈述 - II - 付费
<!-- ko if: IsPaidUser() -->
<!-- ko if: $parent.isEditable($data.UserName, $data.UserRole) -->
<i title="Paid" class="fa fa-toggle-on faIcons green" data-bind="click: function (data, event) { $parent.toggleUserAccountStatus($index(), 'deactivate') }"></i>
<!-- /ko -->
<!-- ko if: !$parent.isEditable($data.UserName, $data.UserRole) --><!-- /ko -->
<i style="display: none;">01</i>
<!-- /ko -->
<!-- ko if: !IsPaidUser() --><!-- /ko -->
根据用户详细信息,Statement-I或Statement-II将保存在状态
中var status = knockoutConditionalStatement;
任务是,
我尝试过类似方法-I,
var status = knockoutConditionalStatement;
var license = false;
if (string.search("title=\"Paid\""))
{
license = true;
}
else
{
license = false;
}
// this code run without any error. but license mode did not analysed.
我也尝试过这种方法-II,(可能是愚蠢的)
if(String == '<!-- ko if: IsPaidUser() --><!-- /ko --><!-- ko if: !IsPaidUser() --><!-- ko if: $parent.isEditable($data.UserName,$data.UserRole) --><i title="NotPaid" class="fa fa-toggle-on faIcons fa-rotate-180toggleOff" data-bind="click: function (data, event) { $parent.toggleUserAccountStatus($index(), 'reactivate')}"></i><!-- /ko --><!-- ko if: !$parent.isEditable($data.UserName, $data.UserRole) --><!-- /ko --><i style="display: none;">00</i><!-- /ko -->')
{
license = true;
}
else
{
license = false;
}
// this code always getting into else{} block
请建议我如何解析淘汰条件声明并预测许可证详细信息。
先谢谢
编辑-1:工作代码:
var status = knockoutConditionalStatement;
var license = false;
if (string.search("title=\"Paid\"") != -1 ) // if found
{
license = true;
}
else // not found
{
license = false;
}