Parse.com, Javascript, 表格

Posted

技术标签:

【中文标题】Parse.com, Javascript, 表格【英文标题】:Parse.com, Javascript, Tables 【发布时间】:2015-08-16 13:02:21 【问题描述】:

我有一个显示存储在 parse.com 服务器中的数据的 javascript 表,我还有一个 ios 应用程序,它也从 iOS 应用程序的同一位置获取相同的数据在表中被选中以将对象 id 存储在 NSString 中以用于其他用途,例如将其添加到最喜欢的列等,但是在 javascript 方面,我在这方面做得不是很成功,可以帮忙吗?

iOS

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[tableView deselectRowAtIndexPath:indexPath animated:YES];
    PFObject *tempObject = [HomeArray objectAtIndex:indexPath.row];
    NSLog(@"%@", tempObject.objectId);
    _NameOfGame.text = [tempObject objectForKey:@"NameGame"];
    _Items.text = [tempObject objectForKey:@"item"];
    _Des.text = [tempObject objectForKey:@"des"];
    userFirstname = [tempObject objectForKey:@"FirstName"];
    group = [tempObject objectForKey:@"group"];
    device = [tempObject objectForKey:@"Device"];
    together = [NSString stringWithFormat:@"Uploaded by %@ from %@ on a %@", userFirstname, group, device];
    PFFile *video = [tempObject objectForKey:@"Video"];
    _videoUrl = video.url;
    NSLog(@"got a video %@", _videoUrl);
    _deleteObjectID = [HomeArray objectAtIndex:indexPath.row];
    NSLog(@"%@", _deleteObjectID);
    [self animateDetailView];

Javascript

    var GameScore = Parse.Object.extend("games");
var query = new Parse.Query(GameScore);
query.equalTo("group", strUser)
query.find(

    success: function(results)
            
        for (var i = 0; i < results.length; i++) 
        
            var object = results[i];

            (function($) 
                $("#first-team-results-table").append("<tr><td>" 
                +"<input type='checkbox' data-id='" + object.id + "'/>" $(checkBox).appendTo("#modifiersDiv")
                + "</td><td>"
                    + object.get("NameGame")
                    + "</td><td>" 
                    + object.get("item") 
                    + "</td><td>" 
                    + object.get("des") 
                    + "</td></tr>");
            )(jQuery);
       
    error: function(error) 
        alert("Error: " + error.code + " " + error.message);
    
)
);

我曾尝试在 javascript 中使用复选框,但没有成功

【问题讨论】:

【参考方案1】:

你在哪些方面没有成功?什么不起作用?

你得到了正确的结果吗?如果不改变这一行

query.equalTo("group", strUser) && query.equalTo("month", res);

query.equalTo("group", strUser);
query.equalTo("month", res);

------------------------------------ 编辑 ---------- ---------------

我会这样重写:

var GameScore = Parse.Object.extend("games"),
    query = new Parse.Query(GameScore),
    $table = $("#first-team-results-table"),
    tableString;

appendToTable = function (object) 
    tableString = "<tr><td><input type='checkbox' data-id='"+object.id+"'</td><td>"+object.get("NameGame")+"</td><td>"+object.get("item")+"</td><td>"+object.get("des")+"</td></tr>";
    $table.append(tableString);
    $(checkBox).appendTo("#modifiersDiv"); // I don't know what the checkbox-variable represents... anyway use this line to do something with it ;)
;

query.equalTo("group", strUser)
query.find(
    success: function(results)
        var object;
        for (var i = results.length - 1; i >= 0; i--) 
            object = results[i];
            appendToTable(object);
        ;
    ,
    error: function (error) 
        alert("Error: " + error.code + " " + error.message);
    
);

我不确定你在这里做什么

$(checkBox).appendTo("#modifiersDiv")

但我希望它能让你朝着正确的方向前进......

------------------------------------ 编辑 ---------- ---------------

好的重试,仍然不确定我是否明白你想要做的事情。以下将首先显示从 Parse.com 获取内容并在单击“更多”按钮时将其放入#objectBox-div 后的表格

HTML

<div id="buttonShow"> <input type="submit" id="uploadPaid" value="More"/><input type="text" id="gotObject" class="textFields"/> </div>
<table id="first-team-results-table"></table>
<div id="objectBox"></div>

JS

(function() 
    var GameScore = Parse.Object.extend("games"),
        query = new Parse.Query(GameScore),
        $table = $("#first-team-results-table"),
        $objectBox = $('#objectBox'),
        tableString,
        divString,
        ParseGames;

    appendToTable = function (object) 
        tableString = "<tr><td><input class='check' type='checkbox' data-id='"+object.id+"'</td><td>"+object.get('NameGame')+"</td><td>"+object.get('item')+"</td><td>"+object.get('des')+"</td></tr>";
        $table.prepend(tableString);
    ;
    appendToDiv = function (object) 
        divString = "<p><span>"+object.get('NameGame')+"</span> <span>"+object.get('item')+"</span> <span>"+object.get('des')+"</span></p>";
        $objectBox.append(divString);
    ;

    query.equalTo("group", strUser)
    query.find(
        success: function(results)
            ParseGames = results;
            for (var i = results.length - 1; i >= 0; i--) 
                appendToTable(results[i]);
            ;
        ,
        error: function (error) 
            alert("Error: " + error.code + " " + error.message);
        
    );

    $("#uploadPaid").on('click', function (e) 
        e.preventDefault();
        $objectBox.html('');
        $('.check').each(function(index) 
            console.log($(this).is(':checked'));
            if ($(this).is(':checked')) 
                appendToDiv(ParseGames[index]);
            ;
        );
    );
)();

祝你好运;)

【讨论】:

嗨@Argee我无法获取每一行的objectid并将其存储到一个var中以供使用我尝试使用复选框但不成功 感谢您的帮助,代码确实有所帮助,但是我尝试使用此代码和 HTML div Javascript $("#uploadPaid").click(function () event.preventDefault (); var OBJECTIDS = $("objectBox").attr("value"); document.addEventListener("DOMContentLoaded", function(event) document.getElementById("gotObject").innerHTML = OBJECTIDS; ) ) ;【参考方案2】:

经过几天浏览网站并尝试大量代码后,我终于得到了问题的答案。

 <table id="first-team-results-table" class="table1" border="1xp" style="width:100%">
        <col >
        <col >
        <col >
        <col >
        <col >
        <tbody>
            <tr>
                <th>Name Of Game</th>
                <th>Item</th>
                <th>Video</th>
                <th>Description</th>
                <th>Group</th>
            </tr>
        </tbody>
    </table>
<script type="text/javascript">
     Parse.initialize("API1", "API2" );

var firstTeamResults = Parse.Object.extend("ukgames");
var query = new Parse.Query(firstTeamResults);
//query.equalTo("favs", id);
//"group" , group
query.descending("updateAt");
query.find(success: function(results)        
        for (var i = 0; i < results.length; i++) 
        
            var object = results[i];

            (function($) 
                $("#first-team-results-table").append("<tr><td>" 
                    + "<input type='checkbox' class='chkNumber' value='"+object.id+"'/>"
                    + "</td><td>"
                    + object.get("NameGame") 
                    + "</td><td>" 
                    + object.get("item") 
                    + "</td><td>"
                    + object.get("des") 
                    + "</td><td>" 
                    + object.get("group") 
                    +"</td></tr>");
            )(jQuery);
       
    ,
    error: function(error) 
        alert("Error: " + error.code + " " + error.message);
    
);
</script>
<div id="buttonShow"> 
    <input type="button" class="btnGetAll" value="More"/>
    <input type="text" id="gotObject" class="textFields"/> 
    </div>
    <script type="text/javascript">    
$(function () 
      $('.btnGetAll').click(function () 
        if ($('.chkNumber:checked').length) 
          var chkId = '';
          $('.chkNumber:checked').each(function () 
            chkId += $(this).val() + ",";
          );
          chkId = chkId.slice(0, -1);
          alert(chkId);
        
        else 
          alert('Nothing Selected');
        
      );

      $('.chkSelectAll').click(function () 
        $('.chkNumber').prop('checked', $(this).is(':checked'));
      );

      $('.chkNumber').click(function () 
        if ($('.chkNumber:checked').length == $('.chkNumber').length) 
          $('.chkSelectAll').prop('checked', true);
        
        else 
          $('.chkSelectAll').prop('checked', false);
        
      );

    );
</script>

【讨论】:

以上是关于Parse.com, Javascript, 表格的主要内容,如果未能解决你的问题,请参考以下文章

将 URL 更改为文件(Parse.com 使用 Javascript CloudCode)

从 Parse.com 云代码(Javascript SDK)获取信息的最佳方式

Parse.com 云代码 - 无法弄清楚为啥 javascript 变量在所有数组项中具有相同的值

使用 Parse 将缩略图图像加载到表格单元格中的问题

将 Java 字符串数组或 JSON 字符串转换为 Javascript 数组(Parse.com Cloud Code 和 Mandrill)

从 Parse.com 查询或保存传入的推送通知