`self.affiliateDescription = ko.observable();
self.connectedTo = ko.computed(function() {
return self.app.translate.get("connectedTo") + ": " + self.affiliateDescription;
});
I assigned affiliateDescription here:
getDataPromise()
.then(function(result) {
console.log(result);
//fetches data from an API and returns a JSON string
var description = result[0].Description;
self.affiliateDescription = JSON.stringify(description);
console.log(self.affiliateDescription); //string prints fine here.
}
});`
`
当我去更新affiliateDescription时,我在控制台中打印它并获取我想要的字符串,但connectedTo计算字符串是"连接到:然后self.affiliateDescription"给了我一堆垃圾无意义代码?
它将这个垃圾放在我的字符串应该在网页上: function observable(){if(arguments.length> 0){//写入//如果值没有改变则忽略写入if(observable.isDifferent(observable [observableLatestValue],arguments [0])){observable .valueWillMutate(); observable [observableLatestValue] = arguments [0]; observable.valueHasMutated();返回这个; //允许链式赋值} else {//读取ko.dependencyDetection.registerDependency(observable); //如果调用者执行了"读取" operation return observable [observableLatestValue]; }}