请在评论部分找到更新的小提琴。
我提供了HTML代码和ViewModel。在更改下拉列表中的值时,我希望更新网格中的点值。为新的下拉值计算点值,但返回值无法将值绑定到网格。
答案 0 :(得分:2)
为了在seats
更改UI中进行dropdownAValue
更改,您需要先声明空的可观察数组:
self.seats = ko.observableArray();
并在订阅功能中更新它,而不是每次都创建新的observableArray
:
self.seats([new PipCalculation(self.rates[0], self.rates[0].price, self.rates, self.newLot[0],currentlotvalue) ]);
答案 1 :(得分:1)
我的回答将是Max Brodin
给出的补充。
我们可以通过执行类似的操作来进一步规范化代码
查看型号:
self.dropdownAValue = ko.observable(0.1);
self.seats = ko.observableArray([]);
var newItems = ko.utils.arrayMap(self.rates,function(item){
return new PipCalculation(item, item.price, self.rates, self.newLot[0], self.dropdownAValue)
});
self.seats(newItems);
//computed code
self.formattedPrice2 = ko.computed(function() {
//alert("hi");
var cur = self.rate().pair;
//var price = self.rate().price;
//alert(self.myQuote());
var price = self.myQuote();
var pip = 1;
var lot1 =currentlotvalue().lotSize;
工作小提琴here
要做的事情:
DD
值实例。还有另一种方法可以做到这一点(我以前做过这样的事情)
self.seats([]);
var mutatedArray = self.seats();
ko.utils.arrayForEach(self.rates,function(item){
mutatedArray.push(new PipCalculation(item, item.price, self.rates, self.newLot[0],self.dropdownAValue)); // push to the array(normal array)
});
self.seats.valueHasMutated();
有关详情,请参阅我的回答here。