dourao1896
2016-01-16 16:18
浏览 182
已采纳

将JavaScript数组存储在数据库中,并在需要时返回数组

I have a multidimensional associative JavaScript array with some metabox data and I need to store that array in the WordPress database (in a single column).

And I also want to get that stored array back in the metabox call back function and use the values in the array to populate the relevant fields.

This is what I've done so far...

    var data = [
        { key: 'cardK', val: 13 },
        { key: 'cardQ', val: 12 },
        { key: 'cardAJ', val: 11 },
    ];
    var serializedData= JSON.stringify( data );

This outputs a string look like this

[[1,2],[3,4],[5,6]]

Now I can store this in the DB in a single column. But how can I get this back as an array and use it to populate the fields ?

图片转代码服务由CSDN问答提供 功能建议

我有一个带有一些元数据数据的多维关联JavaScript数组,我需要将该数组存储在WordPress数据库中( 单列。)</ p>

我还希望将存储的数组放回元数据回调函数中,并使用数组中的值来填充相关字段。 </ p>

这是我到目前为止所做的... </ p>

  var data = [
 {key:'cardK',  val:13},
 {key:'cardQ',val:12},
 {key:'cardAJ',val:11},
]; 
 var serializedData = JSON.stringify(data); \  n </ code> </ pre> 
 
 

输出如下字符串</ p>

  [[1,2],[3,4],  [5,6]] 
 </ code> </ pre> 
 
 

现在我可以将它存储在一列中的数据库中。 但是,如何将其作为数组返回并使用它来填充字段?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题