简体   繁体   English

Backbone.js-在模型中定义json数组

[英]Backbone.js - defining json array within model

here is my model code: 这是我的模型代码:

exports.definition = {

config: {

    columns: {

         "id": "TEXT",

        "nickname": "TEXT",

        "date_of_birth": "TEXT",

        "pictures":[],

        "email":"TEXT",

        "gender": "TEXT",

        "description": "TEXT"

    },

    adapter: {

        type: "sql",

        db_name: "dbname",

        collection_name: "user"

    }

},

For pictures I would like to define a JSON array which will then be populated dynamically. 对于图片,我想定义一个JSON数组,然后将其动态填充。

I have tried pictures: [] but it throws up an error. 我尝试过图片:[]但抛出错误。 What is the best way to do this, thanks 最好的方法是什么,谢谢

Error: 错误:

[ERROR] : line = 15; [错误]:第15行;

[ERROR] : message = "'undefined' is not a function (evaluating 'name.split(/\\s+/)')"; [错误]:消息=“'未定义'不是一个函数(正在评估'name.split(/ \\ s + /)')”“;

[ERROR] : name = TypeError; [错误]:名称= TypeError;

[ERROR] : sourceId = 309198272; [错误]:sourceId = 309198272;

The issue here is that SQLlite does not have support for storing objects into the database. 这里的问题是SQLlite不支持将对象存储到数据库中。

If you find yourself in this situation. 如果您发现自己处于这种情况。 Simply store the JSON string into the database, then get the database object and parse it into a JSON object. 只需将JSON字符串存储到数据库中,然后获取数据库对象并将其解析为JSON对象即可。

Once you have done that, you should be able to access the elements via a for loop. 完成此操作后,您应该能够通过for循环访问元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM