小编Tim*_*ers的帖子

困难的分层排序

我遇到了一个非常困难的排序问题,我想知道是否有人可以帮我解决这个问题.基本上我有一个充满以下信息的SQL表:

ID (The comment's Unique Identifier)

Previous ID (The ID of the comment that is being replied to with this comment)

Position (The position of how "deep" the comment is, a post directly on a 
page would be "1" a reply to that "2", etc.
Run Code Online (Sandbox Code Playgroud)

是否可以使用此信息对C#/ LINQ进行排序,使其在调用时以正确的顺序返回?

一个例子可能如下:

ID | Position | PreviousID | Message|

1  | 1        | 0          | Hello
2  | 1        | 0          | How
3  | 2        | 1          | There!
4  | 2        | …
Run Code Online (Sandbox Code Playgroud)

c# sql linq sorting

5
推荐指数
1
解决办法
110
查看次数

从Parse承诺链返回数据

我想我已经掌握了Parse承诺链,但我不明白的是我如何从函数返回我的数据(i)备份promise链和(ii)返回原始JS代码的调用方法.

使用下面的代码,调用第一个Parse查询,然后是a(),最后是b(),这一切都很好.每个阶段的console.log都用于测试目的,并显示链已按顺序执行.

我现在有3个问题:

  1. 如何从函数a()和函数b()中获取数据,以便我可以在main函数getUserCompetitionTokens()中访问它?

  2. 如何将getUserCompetitionTokens()中的任何数据返回到调用此Parse代码的主程序?

  3. 如果我想从函数a()以及从函数b()到BOTH的数据返回到我的主程序怎么办?


function getUserCompetitionTokens(comp_id) {
    Parse.initialize("****","****");
    currentUser = Parse.User.current();

    user_competition = Parse.Object.extend("UserCompetition");
    var user_comp_query = new Parse.Query(user_competition);
    user_comp_query.equalTo("UserParent", currentUser);
    user_comp_query.find().then(a).then(b);

    function a(user_comp_results) {

        var no_results = user_comp_results.length;
        var id = user_comp_results[0].id;
        console.log("User Competition Output: " + no_results + " results found, first item id: " + id);

        var Competition = Parse.Object.extend("Competition");
        var query = new Parse.Query(Competition);
        return query.get(comp_id, {
            success: function(competition) {
                console.log("COMP - " + competition.id);
            },
            error: function(competition, error) {
                console.log(error);
            }
        });
    } …
Run Code Online (Sandbox Code Playgroud)

javascript return promise chain parse-platform

3
推荐指数
1
解决办法
1708
查看次数

标签 统计

c# ×1

chain ×1

javascript ×1

linq ×1

parse-platform ×1

promise ×1

return ×1

sorting ×1

sql ×1