Angularjs 角度下划线查找子对象

Angularjs 角度下划线查找子对象,angularjs,underscore.js,Angularjs,Underscore.js,我有一个由angular工厂构建的以下数据结构 tournois { tournois { "tournois_id" = "1", "tournois_title"="test",etc..} { "tournois_id" = "2", "tournois_title"="test",etc..} {etc.} 使用下划线J.\u find我无法根据tournois\u id标准使其工作,我得到了未定义的值

我有一个由angular工厂构建的以下数据结构

tournois {
        tournois { "tournois_id" = "1", "tournois_title"="test",etc..}
                 { "tournois_id" = "2", "tournois_title"="test",etc..}
                 {etc.}
使用下划线J.\u find我无法根据tournois\u id标准使其工作,我得到了未定义的值,这意味着找不到任何值

你知道正确的语法吗

baclyApp.factory("tournois",function($http){
//Provider qui recupère la liste des tournois
    var urlphp="http://localhost/cordova/mbacly/www/php/";
    var tournois={};   
    $http.get(urlphp+"getTournois.php").success(function(data)
     {
         tournois.tournois = data;
     })
    return {
        list: function(){
            return tournois;
        },
        find: function(cid){
                (tournois, function(tournoi){return tournois.tournois.tournois_id == cid});

        }

    }
})
使用


您的服务职能部门应使用
。\u查找

工厂

baclyApp.factory("tournois", function($http) {
    //Provider qui recupère la liste des tournois
    var urlphp = "http://localhost/cordova/mbacly/www/php/";
    var tournois = {};
    $http.get(urlphp + "getTournois.php").success(function(data) {
        tournois.tournois = data;
    })
    return {
        list: function() {
            return tournois;
        },
        find: function(cid) {
            return _.find(tournois.tournoi,function(t) {
                return t.tournois_id == cid;
            });
        }
    }
})

您的服务职能部门应使用
。\u查找

工厂

baclyApp.factory("tournois", function($http) {
    //Provider qui recupère la liste des tournois
    var urlphp = "http://localhost/cordova/mbacly/www/php/";
    var tournois = {};
    $http.get(urlphp + "getTournois.php").success(function(data) {
        tournois.tournois = data;
    })
    return {
        list: function() {
            return tournois;
        },
        find: function(cid) {
            return _.find(tournois.tournoi,function(t) {
                return t.tournois_id == cid;
            });
        }
    }
})

我假设您有一个类似于以下内容的数据结构(基于上述内容)

然后,您将按照以下方式使用underline.js中的ux.find函数:

_.find(tournois.tournois, function(t) {return t.tournois_id === 1})
当然,您应该在return语句中删除它,并用cid值替换结尾的static 1,如下例所示:

return {
    find: function(cid){
        return _.find(tournois.tournois, function(t) {return t.tournois_id === cid});
    }
}

我假设您有一个类似于以下内容的数据结构(基于上述内容)

然后,您将按照以下方式使用underline.js中的ux.find函数:

_.find(tournois.tournois, function(t) {return t.tournois_id === 1})
当然,您应该在return语句中删除它,并用cid值替换结尾的static 1,如下例所示:

return {
    find: function(cid){
        return _.find(tournois.tournois, function(t) {return t.tournois_id === cid});
    }
}

我找不到使用
\u find
的地方。您的find()函数体不是有效的JavaScript。而且发布的代码仍然没有在任何地方使用uu.find()。我没有找到一个地方..在那里使用了
\u find
您的find()函数体不是有效的JavaScript。而且发布的代码仍然没有在任何地方使用u.find()。我很高兴听到这个消息。如果可以的话,请记下我的答案。我记下了,但我太新了,还不能算出来。我很高兴听到这个消息。如果可以的话,请记下我的答案。我记下了,但我太新了,还没算上。