gpt4 book ai didi

radio-button - 使用 knockout.js 禁用单选按钮

转载 作者:行者123 更新时间:2023-12-04 06:16:04 31 4
gpt4 key购买 nike

如何使用 knockout.js 禁用单选按钮?我不希望用户能够选择它。我下面的模板不起作用。

<div id="answers" data-bind="template: { name: 'answerTmpl', data: interactive.answers }">
</div>

<script id="answerTmpl" type="text/html">

{{each(index, value) $data}}
<div>
<input type="radio" value="${index}" name="Answer" data-bind="disable: app.viewModel.avatars.speaking, checked: app.viewModel.interactive.answerSelected"/> <span>${value}</span>
</div>
{{/each}}
</script>

app.avatars.js
(function (app, $, undefined) {

app.viewModel = app.viewModel || {};

app.viewModel.avatars = {
speaking: ko.observable(false),
loaded: ko.observable(false)
};

app.interactive.js
(function (app, $, undefined) {

app.viewModel = app.viewModel || {};

app.viewModel.interactive = {
timeout: 1500,
answers: ko.observableArray(),
answerSelected: ko.observable(''),
correctAnswer: ko.observable(-1),
bookPage: ko.observable(1),
chapterEmail: ko.observable(''),
trialogue: {
inProgress: ko.observable(false),
response: ko.observable(''),
conversation: ko.observableArray()
}
};

app.interactive.init = function () {
ko.applyBindings(app.viewModel);
};

最佳答案

当您使用全局变量而不是绑定(bind)数据时,您似乎需要显式评估函数:http://jsfiddle.net/nFgnj/

<input type="radio" value="${index}" name="Answer" 
data-bind="disable:app.viewModel.avatars.speaking(),
checked:app.viewModel.interactive.answerSelected()" />

我不太喜欢这个解决方案,因为它依赖于 app作为一个全局变量。

关于radio-button - 使用 knockout.js 禁用单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7236940/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com