<script type="text/javascript">
var cartList = (@Html.Raw(@ViewData["json"])); //接收后台Json数据
for(var item in cartList) //针对数组不能实时刷时解决方法,遍历Json
{
var p=cartList[item].Price;
var c=cartList[item].Count;
cartList[item].Price=ko.observable(p); //将价格转化为可监视类型
cartList[item].Count=ko.observable(c); //将数量转化为可监视类型
}
function formatPrice(value)
{
return value.toFixed(2);
}
function countPrice(price,count)
{
return formatPrice(price * count);
}
var myCartList=function(){
var self=this;
self.list=ko.observableArray(cartList);
self.removeLine=function(){
KnockoutJs (二)实时刷新,数组不能刷新解决办法
最新推荐文章于 2024-06-28 23:33:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)