1

Stack:

  • ASP MVC4 Beta
  • Web API
  • Knockout.js
  • Upshot.js

I have a master-detail scenario. In the master part, I'm editing a Order and on the details part i have the orders products. I can list all the products I have and that works great, but I now need to display the master and details.

This is my Web API method:

 public Order GetSingleOrder(long orderId)
 {
     return DbContext.Orders
                         .Include("OrderedProducts")
                         .Include("OrderedProducts.Product")
                         .Include("OrderedProducts.Product.Family")
                         .Single(o => o.OrderId == orderId);
 }

This works nice, it returns only one order with products and it's info.

But in the viewModel, I can't get this as single order, upshot datasource only provides a method called getEntities() and can't get to it's items.

var CreateOrEditViewModel = function () {
    var self = this;
    self.dsOrder = upshot.dataSources.SingleOrder.refresh();

    self.orders = self.dsOrder.getEntities();
    self.order = self.orders()[0];

};

it appears its lazy loaded and at the time getEntities() is called it does not have any items and self.orders() returns a empty collecton.

Update: I need a way to get one order, bind to that order, let the user update it's fields, and save it through the datasource.

4

1 回答 1

3

它不是延迟加载的,而是异步的。当您调用 upshot.dataSources.SingleOrder.refresh() 时,您可以传入两个回调函数,一个用于成功,一个用于错误。在回调中,您将拥有加载的数据。

于 2012-03-12T20:11:22.717 回答