gpt4 book ai didi

javascript - Knockout 数据绑定(bind)不更新来自选择绑定(bind)的自定义事件

转载 作者:行者123 更新时间:2023-11-29 21:58:13 25 4
gpt4 key购买 nike

我在通过 select 元素更改时调用的自定义事件更新 data-bind 时遇到问题。这个想法是 select 元素发生变化,从而更新 datatype 参数。然后 change 事件启动,其中更新 sliderType 这是一个 bool 值,如果选择了特定值则更改为 true。一切正常,但是 div -data-bind="if: sliderType- 不会在更改时更新,但它会在页面加载时工作。

有没有办法强制页面重新检查绑定(bind)?

这是一段代码,可以让您了解我的结构。

HTML

<select data-bind="options: Items, optionsText: 'type', value: dataType, optionsCaption: 'Choose Data Item...', event: { change: dataTypeChange }"></select>
<div data-bind="if: sliderType">Here is a message. Astonishing.</div>

JavaScript

dataTypeChange: function() {this.sliderType = (this.dataType._latestValue.id == 6) ? true : false;

ko.observable 被使用:

{
dataItemId: -1,
name: ko.observable(res.Text),
dataType: ko.observable(res.DataType),
dataTypeChange: function() {
this.sliderType = (this.dataType._latestValue.id == 6) ? true : false;
},
sliderType: sliderActive
}

最佳答案

我犯了一个愚蠢的错误,如果 data-bind 对象是一个可观察对象,那将会有所帮助

{
dataItemId: -1,
name: ko.observable(res.Text),
dataType: ko.observable(res.DataType),
dataTypeChange: function() {
this.sliderType = (this.dataType._latestValue.id == 6) ? true : false;
},
sliderType: ko.observable(sliderActive)
}

关于javascript - Knockout 数据绑定(bind)不更新来自选择绑定(bind)的自定义事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325320/

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