淘汰赛自举没有加载

时间:2016-11-21 10:44:07

标签: knockout.js bootstrap-multiselect bootstrap-tags-input

我有一个基于knockout.js的网站。 我有一个标签输入提交了一个多选元素。 如果在负载下显示,则一切正常。 但我想在用户点击按钮时显示它们。

我该怎么做?

由于

<!-- ko if: state=="EDIT" -->
//the default state is not that. Here should appear the tagsinput, but if it's here, don't works
<!-- /ko -->
<input id="domains" type="text" value="" data-role="tagsinput" placeholder="Add tags" />

1 个答案:

答案 0 :(得分:1)

state必须是可观察的(ko.observable()),您需要调用来获取其值:if: state() === 'EDIT'

示例:

&#13;
&#13;
ko.applyBindings({
  state: ko.observable("DEFAULT")
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<!-- ko if: state() === "EDIT" -->
<h1> Edit section </h1>
<!-- /ko -->

<!-- ko if: state() === "DEFAULT" -->
<h1> Default section </h1>
<!-- /ko -->

<button data-bind="click: state.bind(null, 'EDIT')">Edit</button>
<button data-bind="click: state.bind(null, 'DEFAULT')">Default</button>
&#13;
&#13;
&#13;