2012-03-08 63 views

回答

3

您正在设置quantity属性不正确。 quantityko observable,所以你需要使用的语法:

 self.sellIt = function (product) { 
      $.post('/Product/SellIt', { id: product.id }, 
      function (data) { 
       var res = Enumerable.From(self.products) 
          .Where("i => i.id == " + data.Id) 
          .Select("s => s"); 

       res.quantity(data.Quantity); // this is the important bit!! 
      }); 
     }; 

不过,我想你也许会缩短你的代码下降到只有:

 self.sellIt = function (product) { 
      $.post('/Product/SellIt', { id: product.id }, 
      function (data) { 
       product.quantity(data.Quantity); 
      }); 
     };