0

以下是我的 json 数据 URL http://bluestonesolutions.in/Connect4mJson/GetEmployees.svc/getnotice?InstanceId=604&EnoticeType=Flash%20News&UserID=112730&IsGlobalNotice=0

我想使用 jquery Mobile for Phonegap 在表中显示数据。我可以轻松获取数据,但可以在移动设备中显示。

这是工作示例。请指导我如何解析它的phonegap

$(document).ready(function() {
    $.ajax({
        url : 'http://bluestonesolutions.in/Connect4mJson/GetEmployees.svc/getnotice?InstanceId=604&EnoticeType=Flash%20News&UserID=112730&IsGlobalNotice=0',
        type : 'GET',
        dataType : 'JSON',
        crossDomain: true,
        success : function(data) {      
            document.write('<table width="400" height="288" align="center"  style="border:5px solid #10A3D8; ">')
            $.each(data, function() {
                console.log(this.Subject);
                document.write('<tr style="background:#D4D2D2;" >')
                document.write('<td style="color:#041DB3;">'+'Subject:-</td>')
                document.write('<td style="color:#041DB3;">'+this.Subject+'</td>')
                document.write('</tr>')
                document.write('<tr style="background:#04A273;">')
                document.write('<td>'+'Description:-</td>')
                document.write('<td>'+this.ENoticeDescription+'</td>')
                document.write('</tr>')
            });
            document.write('<table>');          
            // open console debugging tools on google and see the parse value
        },
        error : function() {}
    });
});
4

3 回答 3

2

尝试使用它来解析 JSON

jQuery.parseJSON()
于 2015-04-02T12:25:27.830 回答
0

您可以解析 JSON,如 var JsonStringify_ExecResData = JSON.stringify(data); var obj = jQuery.parseJSON(JsonStringify_ExecResData);

和喜欢

localStorage.setItem("userEmail", userEmail);

您可以设置参数并进入另一个页面,例如

localStorage.setItem("userEmail", userEmail);

于 2015-04-02T12:32:27.850 回答
0

我不是 Phonegap 方面的专家,但这是您在 jQuery 中为您的特定场景创建/填充表的方式。然后,您可以将表格附加到页面上的现有元素,或者像我一样,附加到正文(因为它是一个演示)。调整此代码以满足您的需要,例如替换我的代码之间的所有内容success : function(data) {})除了var dat = [....];

var data = [{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19619,"NoticeDocument":"","Subject":"Singing competitions will be conducted this Month, interested candidates can come to office room and enroll.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19623,"NoticeDocument":"","Subject":"Flowers day celebrations will be conducted on 1st Saturday of next Month, Students are instructed to bring 5 different Flowers.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19624,"NoticeDocument":"","Subject":"Painting competitions for Senior Program will be conducted on 30th of this month.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"Debate competition for Senior class students will be conducted on 2nd of April month, interested students contact Head of Senior Program Staff.","ENoticeId":19660,"NoticeDocument":"","Subject":"Senior Program - Debate Competition","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"}];

var $table = $('<table width="400" height="288" align="center"  style="border:5px solid #10A3D8;">');
var $trs = $();
$.each(data, function() {
    var $tr = $("<tr/>").css("background", "#D4D2D2");
    var $td = $("<td/>").css("color", "#041DB3").text("Subject:");
    $tr.append($td);
    $td = $("<td/>").css("color", "#041DB3").text(this.Subject);
    $tr.append($td);
    $trs = $trs.add($tr);
    
    $tr = $("<tr/>").css("background", "#04A273");
    $td = $("<td/>").css("color", "#041DB3").text("Description:");
    $tr.append($td);
    $td = $("<td/>").css("color", "#041DB3").text(this.ENoticeDescription);
    $tr.append($td);
    $trs = $trs.add($tr);
});
$table.empty().append($trs);
$("body").empty().append($table);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

使用 CSS 类而不是.css("prop", "value")因为当您有 100 个元素时它会影响性能。对于这种特定情况没关系,因为数据不是那么大。但是,我仍然建议你使用类。

于 2015-04-02T13:04:18.580 回答