![](/img/trans.png)
[英]write a function that returns all of the users names and roles. Don't understand what I'm doing wrong
[英]What is this function doing? i'm most confused with the Read and write part
我知道这是一个构造函数,但我没有读写部分。.我知道它具有if和else语句,但是我对其工作感到困惑!
self.CondInspecChks_RevValve_UI = ko.computed({
read: function () {
return self.CondInspecChks_RevValve() == 1 ? true : false;
},
write: function (newValue) {
self.CondInspecChks_RevValve(newValue ? 1 : 0);
}
});
这是计算出的可观察值的敲除 -它允许将动态值分配给KO可观察值 。
const normalObservable = ko.observable("hello"); const computedObservable = ko.computed(function() { return "my dynamic value is: " + normalObservable(); }) console.log(normalObservable()) console.log(computedObservable()) //update the observable normalObservable("world"); console.log(normalObservable()) //the computed also changed console.log(computedObservable())
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
在这种特殊情况下,这是使用计算的高级构造使其可写的 。
const someWriteableValue = ko.observable("hello") const computed = ko.computed({ read: function () { return "my dynamic value is: " + someWriteableValue(); }, write: function (value) { someWriteableValue(value); } }) console.log(computed()); //update the computed computed("world"); console.log(computed());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
这是一个可计算的可观察的knockoutjs。
它依赖于一个称为CondInspecChks_RevValve
的基础可观察属性,该属性是数字(1或0),并且CondInspecChks_RevValve_UI
问题中的可观察CondInspecChks_RevValve_UI
返回true
或false
并允许您对其进行写入,这将适当地更新基础属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.