将具有多个值的 JSON 字符串发布到 ext js 面板

Posting a JSON string with multiple values to ext js panel

本文关键字:ext 面板 js 字符串 JSON      更新时间:2023-09-26

我正在开发一个应用程序的元素。我有一个小型网络应用程序,专门用于跟踪企业的客户。目前我的能力非常有限。我将注释与其他属性一起存储在客户端表中。我决定尝试通过添加一个笔记表并使用笔记更新 ext js 面板来让它变得更好。

如果我的笔记查询中只有一个笔记,一切正常。

否则我会收到此错误。

SyntaxError: invalid property id
..._date":"2013-10-08","note_body":"abcd"},{"username":"rcox","bdev_firstname":"Tre...

这是我正在使用的 PHP。

case 'note':
$userid = $_REQUEST['clientID'];
$query = $dbh->prepare("SELECT a.username, b.bdev_firstname, b.bdev_lastname, n.note_date, n.note_body FROM admin a, bdevs b, clients c, notes n WHERE  c.clientID=".$userid.";");
$query->execute();
while($cli = $query->fetch()) {
$json = '{"username":"'.$cli['username'].'","bdev_firstname":"'.$cli['bdev_firstname'].'","bdev_lastname":"'.$cli['bdev_lastname'].'","note_date":"'.$cli['note_date'].'","note_body":"'.$cli['note_body'].'"},';   
$note .= $json;
}
$note = trim($note, ',');
echo '{success: true, data:'.$note.'}';   
break;

这是我的ext js函数。

function getNote(){
    var selectedNote = userGrid.getSelectionModel().getSelected();
    Ext.Ajax.request({
        url: 'inc/template.php',
        params: {list: 'note',
                clientID: selectedNote.get('clientID')
                },
        method: 'POST',
        success: function(f,a){
            var jsonData = Ext.util.JSON.decode(f.responseText);
                if(jsonData.success == true)
                {
                    var username = jsonData.data.username;
                    var bdev_firstname = jsonData.data.bdev_firstname;
                    var bdev_lastname = jsonData.data.bdev_lastname;
                    var note_date = jsonData.data.note_date;
                    var note_body = jsonData.data.note_body;
                    RightPanel.update('<b>Admin:</b> ' + username + '<br/><b>Buissiness Dev Rep:</b> ' + bdev_firstname + bdev_lastname + '<br/><b>Note Date:</b> ' + note_date + ' <br/>----------<br/> ' + note_body);
                }
                else
                {
                    RightPanel.update('Access Denied');
                }
        },
        failure: function(f,a){
            Ext.Msg.alert("Error", "Access Denied");
        }
    });
}

这个问题已在下面得到解答。有关此主题的更多故障排除,请访问我在Sencha论坛上的问题。http://www.sencha.com/forum/showthread.php?273478-MOVED-POST-Posting-a-JSON-array-with-multiple-values-to-ext-js-panel&p=1002545#post1002545

如果你实际上不使用它,那么使用 json 有什么意义。

case 'note':
$userid = $_REQUEST['clientID'];
$query = $dbh->prepare("SELECT a.username, b.bdev_firstname, b.bdev_lastname, n.note_date, n.note_body FROM admin a, bdevs b, clients c, notes n WHERE  c.clientID = ?");
$query->execute(array($userid));
$response = json_encode(array('success'=> true, data => $query->fetchAll(PDO::FETCH_ASSOC)));
echo $response;   
break;

然后ext.js你的错误所在 - 如果数据是一个数组,你需要迭代它,然后才能访问关联字段,对吧?

            if(jsonData.success == true)
            {
                var i, item;
                for(  i = 0; i < jsonData.data.length; i++; ) {
                item = jsonData.data[i];                    
                RightPanel.update('<b>Admin:</b> ' + item.username + '<br/><b>Buissiness Dev Rep:</b> ' + item.bdev_firstname+" "+item.bdev_lastname + '<br/><b>Note Date:</b> ' + item.note_date + ' <br/>----------<br/> ' + item.note_body);
              }
            }