2015-06-30 4 views
0

вот мой код, чтобы сохранить значения с помощью JSне может прочитать данные неопределенного? JSON

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 не работает, когда я послал значения от верхнего контроллера, чтобы сохранить durring debuuging я проверить формат Boths формат был тот же, что я должен сделать, чтобы синхронизировать значения, так что на стороне сервера получает их Updation

здесь формат в консоли отладки как для text1 и text2

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

ответ

0

глядя вам закодировать только одно приходит на ум, что в vm_Currencies.sele ctedRow.CurrencyCode является «неопределенным».

YOU может отладчик браузера пользователя проверить значение во время выполнения. А также попробовать этот

if(vm_Currencies.selectedRow.CurrencyCode != "undefined") 
{ 
//Code Here 
} 

другой вариант

if(vm_Currencies != "undefined") 
{ 
//Code here 
} 
+0

код совершен я получаю значение валюты коды даже я редактировал вопрос теперь проверять комментарии –

+0

почему это не aceepting код валюты их является только проблема с этим –

1
 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(); 
       } 

      } 
Смежные вопросы