angular factory,then()中的return语句将返回undefined

时间:2015-07-13 17:27:37

标签: javascript angularjs

我使用MakeBusMarkers(orderedFilteredData)在我的控制器中调用以下工厂。

Console.log(mark)返回一个有效对象(在return语句之前调用)。 我假设一个简单的答案,但我做错了什么?

.factory('MakeBusMarkers', ['busesByDepot', '$timeout', 'CamelToString', function(busesByDepot, $timeout, CamelToString){

// make leaflet map markers from filtered data

return function(orderedFilteredData){
    var mark = {};

    busesByDepot.then(function(keyMap){     
        orderedFilteredData.forEach(function(currentVal){
            mark[currentVal.num] = {
                message : '#' + currentVal.num.toString()
            }

            ...some additional code here...

        console.log(mark);
        return mark;
    });
}

}])

1 个答案:

答案 0 :(得分:0)

正确,

然后工厂返回一个promise对象。谢谢。

import pandas as pd
import numpy as np

# your data
# =============================
df1 = pd.DataFrame({'A': [1,2,3,1],
                    'B': [1,4,1,2],
                    'C': ['test1','test2','test3','test4']
                    })
print(df1)


   A  B      C
0  1  1  test1
1  2  4  test2
2  3  1  test3
3  1  2  test4

# processing
# =====================================
mask = df1.B == 1

df1[mask | ((df1.A.isin(df1[mask].A)) & (df1.B==2))]


   A  B      C
0  1  1  test1
2  3  1  test3
3  1  2  test4