【问题标题】:Displaying JSON data in jQuery accordion在 jQuery 手风琴中显示 JSON 数据
【发布时间】:2014-02-14 03:28:16
【问题描述】:

我正在开发一个新的应用程序,并决定尝试使用 jQuery EasyUI 来简化我的工作。我正在取得进步,但我肯定已经过头了。这是一种边学边做的努力。

我在这里: 我已经能够提取基本联系信息并将其填充到 jQuery 对话窗口中。我正在使用这些选项卡之一中的选项卡和手风琴自定义对话框。我的问题是手风琴正在显示 JSON- 而我似乎无法格式化它。

这是本节的代码:

function editUser(){
        var row = $('#dg').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('setTitle','Prospect Details');
            $('#fm').form('load',row);
            url = 'update_user.php?id='+row.id;
            $('#dia_name').html(row.Name);
            var phone = phoneFormat(row.Phone);
            $("#dia_phone").html(phone);
            if (row.message_duration > 0) {
                $('#hangup').hide();
                $('#message').show();
                $('#msg_txt').show();
            } else {
                $('#hangup').show();
                $('#message').hide();
                $('#msg_txt').hide();
            }
            var pp = $('#aa').accordion('getSelected'); // get the selected panel
            if (pp){
                pp.panel('refresh','contact_history.php?phone='+row.Phone); // call 'refresh' method to load new content
                var txt1=$("<p>Time: ").text(contact_dt);
                var txt2=$("</p><p>Method: ").text(method);
                var txt3=$("</p><p>Who: ").text(who);
                var txt4=$("</p><p>Note: ").text(note);
                $("#hist_title").append(txt1);
                $("#hist_item").append(txt2,txt3,txt4);
            }
        }
    }

这里是手风琴的 HTML 部分:

<div id="aa" class="easyui-accordion" style="width:300px;height:200px;">
                <div title="Title1" data-options="iconCls:'icon-save'" style="overflow:auto;padding:10px;">
                <p>Test</p>
                </div>
                <div id="hist_item" title="Title2" data-options="iconCls:'icon-reload',selected:true" style="padding:10px;">
                content2
                </div>
                <div title="Title3">
                content3
                </div>
                </div>

那么现在……我在这里犯了哪些非常明显和愚蠢的错误?再次提前感谢您帮助我度过难关。

【问题讨论】:

  • 应该在哪里读取 JSON?
  • 如何从服务器获取数据..?

标签: php jquery json jquery-easyui


【解决方案1】:

无论你的 JSON 来自哪里,你都必须先解析它:

var data = JSON.parse(incomingData);

那么,它就是一个数组,你可以为所欲为::

$("#hist_title").append(data['title']);

或者

$("#hist_title").text(data['title']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 2013-01-20
    • 1970-01-01
    相关资源
    最近更新 更多