2017-06-14 34 views
0

在我的Ui5應用程序中,我添加了使用oData的CREATE操作。但是,當我嘗試創建條目時,它被添加到後端,但在表中顯示無數據(請參閱圖1)。但是當我刷新相同的頁面時,它就在那裏(參考圖2)。使用單個條目時,它會自動刷新 問題與多個條目。創建記錄後刷新表中的數據

請參考截圖和代碼以獲得清晰的視圖。

刷新網頁後:

點擊創建按鈕後

onCreate: function() { 
    var oModel = this.getView().getModel(); 

    var contactEntry1 = { 
     ProductID: 'KT-1960', 
     TypeCode: 'AD', 
     SupplierID: '0100000001', 
     TaxTarifCode: 1, 
     Category: 'Notebooks', 
     MeasureUnit: 'EA', 
     CurrencyCode: 'EUR', 
     Name: 'Urvish', 
     Description: 'First batch entry', 
    }, 

    contactEntry2 = { 
     ProductID: 'KT-1982', 
     TypeCode: 'AD', 
     SupplierID: '0100000001', 
     TaxTarifCode: 1, 
     Category: 'Notebooks', 
     MeasureUnit: 'EA', 
     CurrencyCode: 'EUR', 
     Name: 'Urvish', 
     Description: 'Second batch entry', 
    }; 

    oModel.setUseBatch(true); 
    oModel.create('/ProductSet', contactEntry1); 
    oModel.create('/ProductSet', contactEntry2); 


    oModel.refresh(true); 


}, 
+1

您可以更新模型並再次調用'setModel' ... – Rayon

+0

嗨人造絲,對不起,延遲。我已經嘗試過,但它不起作用。 – Urvish

回答

0

看起來像您使用異步操作創建,但認爲他們是同步的。

爲了解決這個問題了,你可以把這些2 在一個批處理請求創建,但使用ODataModel的createEntry方法,以使用的SubmitChanges方法,它的回調,將一旦兩個項目的成功在後端側形成被稱爲(下面的代碼示例應ODataModelV2是相關的):

// get the table 'items' aggregation binding, to be able to refresh it later on 
var oTableItemsBinding = oTable.getBinding("items"); 

// define the group id, which will be used later on 
oModel.setDeferredGroups(["createProductGroup"]); 

// create two entries one by one, specifying the 'groupId' parameter 
oModel.createEntry("/ProductSet", { 
    properties: contactEntry1, 
    groupId: "createProductGroup" 
}); 

oModel.createEntry("/ProductSet", { 
    properties: contactEntry2, 
    groupId: "createProductGroup" 
}); 

// send 2 requests in one $batch, passing the name of the 'groupId' and the 'success' callback 
oModel.submitChanges({ 
    groupId: "createProductGroup", 
    success: function() { 
     oTableItemsBinding.refresh(); 
    } 
}); 

如果服務不支持批量請求,那麼你仍然可以使用創建方法, 但利用它的成功回調以確保該條目已被保留在後端,然後更新表的綁定。

相關問題