内容丰富的内容管理(节点lib):条目不会更新

时间:2017-02-18 11:55:27

标签: react-native contentful

标题说全部。我想我已经尝试了所有可能的组合,但它们似乎都没有效果。

我做错了什么?

第一:

client.getSpace('<SPACEID>')
.then((space) => {
         space.updateEntry({
         "sys": {
         id: "<ENTRYID>",
         version:45
          },
         "fields": {
         "job": {
           "fr-FR": "blablabla"
            }
         }
     })
})

=&GT;未处理的promise promise TypeError:space.updateEntry不是函数

第二:

client.getSpace('<SPACEID>')
        .then((space) => {
          space.getEntry(<ENTRYID>)
            .then((entry) => {
                var ver = entry.sys.version
                var id = entry.sys.id
                entry = {
                    "sys":{
                        id: id,
                        version:ver
                    },
                    "fields": {
                        "job": {
                            "fr-FR": "blablabla"
                        }
                    }
                }
                entry.update()
            })
        })

=&GT;得到了entry.update()不是函数

第三:

.then((space) => {
  space.getEntry(entryId)
    .then((entry) => {
        entry.fields.job = {"fr-FR": "blabla"}
        entry.update()
    })
})

=&GT;得到异常&#39; - [__ NSCFNumber长度]:无法识别的选择器发送到实例0xb0000000000002d3&#39;

第四:

entry.fields.job['fr-FR'] = 'blabla'

=&GT;相同的例外

ExceptionsManager.js:78 Exception '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000013' was thrown while invoking sendRequest on target RCTNetworking with params (
        {
        data =         {
            string = "{\"fields\":{\"fireid\":{\"fr-FR\":\"bla\"},\"commission\":{\"fr-FR\":\"bla\"},\"dep\":{\"fr-FR\":\"bla\"},\"desc\":{\"fr-FR\":\"bla\"},\"email\":{\"fr-FR\":\"thp@ggg.com\"},\"firstname\":{\"fr-FR\":\"firstname\"},\"job\":{\"fr-FR\":\"blabla\"},\"name\":{\"fr-FR\":\"name\"},\"tel\":{\"fr-FR\":\"0675234573\"},\"type\":{\"fr-FR\":\"Collaborateur\"}}}";
            trackingName = unknown;
        };
        headers =         {
            accept = "application/json, text/plain, */*";
            authorization = "Bearer TOKEN";
            "content-type" = "application/vnd.contentful.management.v1+json";
            "x-contentful-user-agent" = "contentful-management.js/1.3.1";
            "x-contentful-version" = 1;
        };
        incrementalUpdates = 0;
        method = PUT;
        responseType = text;
        timeout = 0;
        url = "https://api.contentful.com:443/spaces/<SPACEID>/entries/<ENTRYID>";
    },
    139
)

1 个答案:

答案 0 :(得分:0)

要更新条目,您可以执行以下操作: 首先,您需要输入对象,您可以创建它,也可以通过id获取和输入:

// You can get an Entry object by
// 1. Creating one
var myEntry
space.createEntry({}).then((entry) => {myEntry = entry})

// 2. Get an existing one
space.getEntry('ENTRY_ID').then((entry) => {myEntry = entry})

// to Update an entry you can do the following
entry.fields.name['en-US'] = 'Blog Post'
entry.update()
.then(entry => console.log(entry.fields.name['en-US']))

再次取决于您输入的字段,如果您没有本地化内容,则可能不需要[en-US]