有一个带有某些默认值的全局变量,但是在某些函数中已将其重新分配。有一个对象要分配给更新的全局变量值。
尝试过函数返回值,也没有将对象放入函数中,但这两种方法都无法正常工作。面临的挑战是,在为所有对象和变量赋值之后,javascript中的函数将在稍后运行
//variable declaration(myObservable )
var myObservable = ko.observable('66');
//function definition
self.PortfolioPerformance_getval = function () {
$.getJSON("/oracle-html-final/web/js/model/portfolioPerformance.json").then(function (deals) {
var tempCols = [];
var tempCols1 = [];
for(var property in deals.item[0]) {
self.portmax(parseInt(deals.item[0].target));
self.myObservable = ko.observable(self.portmax());
alert('jj'+myObservable());
target_textval = parseInt(deals.item[0].target);
console.log('dddd'+target_textval);
self.portfolioPerformance_Value(parseInt(deals.item[0].portfolio_per_val));
console.log("jinn"+deals.item[0].portfolio_per_val);
self.h_val(deals.item[0].net_profit);
// self.portfolioPerformance_Target = ko.observable({text: 'Target: '+ this.a});
}
}).fail(function(req, status, error) { alert('getJSON failed: ' + status); })
}
self.PortfolioPerformance_getval();
//object where the value is to be reassigned
self.portfolioPerformance_Target = ko.observable({
text: 'Target: '+ myObservable(),
"textType": "number",
style: {
color: '#666666',
fontSize: '14px'
},
rendered: 'on',
/* converter: converterFactory.createConverter({
style: 'currency',
currency: 'USD'
})*/
});