这是我的代码来使用js保存值

 self.Save = function (e) {

    if (vm_Currencies.selectedRow.CurrencyName == null) {
          alert("Fill Some Thing");
    }
    if (vm_Currencies.selectedRow.CurrencyCode != null) {
        debugger;

        var text1 = { "CurrencyCode": vm_Currencies.selectedRow.CurrencyCode, "CurrencyName": vm_Currencies.selectedRow.CurrencyName, "CurrencySign": vm_Currencies.selectedRow.CurrencySign, "DecimalPlaces": vm_Currencies.selectedRow.DecimalPlaces, "PositiveFormat": vm_Currencies.selectedRow.PositiveFormat, "NegativeFormat": vm_Currencies.selectedRow.NegativeFormat, "CurrencyStatus": vm_Currencies.selectedRow.CurrencyStatus };
        self.dsProduct.add(text1);
       ///////////error comes here while i call sync()
        self.dsProduct.sync();
     ////cannot read data of undefined
    }
    if (e.data.CurrencyName != null) {
        debugger;
        var text2 = { "CurrencyName": e.data.CurrencyName, "CurrencySign": e.data.CurrencySign, "DecimalPlaces": e.data.DecimalPlaces, "PositiveFormat": e.data.PositiveFormat, "NegativeFormat": e.data.NegativeFormat, "CurrencyStatus": e.data.CurrencyStatus };
        self.dsProduct.add(text2);
      /////////sucess
        self.dsProduct.sync();
      /////sucess
    }

}


当我向顶级控制器发送值以保存在调试期间保存文本时,text2有效,但text1不起作用

这是text1和text2的控制台调试格式

   CurrencyCode: 20
   CurrencyName: "dollar"
   CurrencySign: "$"
   CurrencyStatus: "23"
   DecimalPlaces: 1
   NegativeFormat: "12"
   PositiveFormat: "12"
__proto__: Object

最佳答案

       self.Save = function (e) {
                    debugger;
                    if (vm_Currencies.selectedRow.CurrencyCode == null)
                    {
                        var GetValuesForSaving = { "CurrencyName": e.data.CurrencyName, "CurrencySign": e.data.CurrencySign, "DecimalPlaces": e.data.DecimalPlaces, "PositiveFormat": e.data.PositiveFormat, "NegativeFormat": e.data.NegativeFormat, "CurrencyStatus": e.data.CurrencyStatus };
                    self.dsProduct.add(GetValuesForSaving);
                    self.dsProduct.sync();
                    }

                    else
                    {
                        debugger;
                        var GetValuesForSaving = { "CurrencyC": vm_Currencies.selectedRow.CurrencyCode, "CurrencyName": vm_Currencies.selectedRow.CurrencyName, "CurrencySign": vm_Currencies.selectedRow.CurrencySign, "DecimalPlaces": vm_Currencies.selectedRow.DecimalPlaces, "PositiveFormat": vm_Currencies.selectedRow.PositiveFormat, "NegativeFormat": vm_Currencies.selectedRow.NegativeFormat, "CurrencyStatus": vm_Currencies.selectedRow.CurrencyStatus };
                        self.dsProduct.add(GetValuesForSaving);
                    self.dsProduct.sync();
                }

            }

10-07 21:11