2013-12-19 31 views
-1

我有websql表獲取數據從我使用JayData和寫這JayData排序依據功能產生奇怪的結果

_context.FoodLog.include("FoodItem").orderByDescending("it.TotalCalories").toArray().then(function(foodLogs) 
{ 
    $scope.$apply(function() 
    { 
     try 
     { 
      for(var i=0; i<foodLogs.length; i++) 
      { 
       console.log(foodLogs[i].TotalCalories);        
      } 
     } 
     catch(error) 
     { 
      console.log("Inner Try "+error); 
     } 
    }) 
}); 

在控制檯的結果是

738.00 
31.56   // why this 31.50 comes before 127.91 and 101.81 
127.91 
101.81 
10.00 
10.00 

但它表明結果 - 不按特定順序設置

更新 表結構

$data.Entity.extend('SpookyHealthAppModel.FoodLog', { 
'FoodLogID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, 
'Quantity': { 'type':'Edm.String','maxLength':5 }, 
'TotalCalories': { 'type':'Edm.String','maxLength':10 }, 
'DateTime': { 'type':'Edm.DateTime' }, 
'ImageCol': { 'type':'Edm.String','maxLength':50 }, 
'Sync': { 'type':'Edm.Boolean' }, 
'FoodItem': { 'type':'SpookyHealthAppModel.FoodItem','required':true,'inverseProperty':'FoodLog' }, 
'User': { 'type':'SpookyHealthAppModel.User','required':true,'inverseProperty':'FoodLog' } 
}); 
+0

@票唐納 請指明原因或錯誤,否則它會對我真的有幫助 – Blu

+0

可能他還沒有明白如此低估... – user2794034

回答

1

我發現我的問題:) 根據我的表結構,我的查詢工作正常 因爲我把order by條款領域擁有String DataType和結果根據串是爲了如果我想導致數字順序改變這一行

'TotalCalories': { 'type':'Edm.String','maxLength':10 }, 

這個

'TotalCalories': { 'type':'Edm.Int32'}, // No need to define length now if you want in float then define float instead of int