0

标题说明了一切。我想我已经尝试了所有可能的组合,但它们似乎都不起作用。

我究竟做错了什么 ?

第一的 :

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

=> 未处理的承诺拒绝类型错误: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()
            })
        })

=> 得到 entry.update() 不是一个函数

第三 :

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

=> 得到异常'-[__NSCFNumber 长度]:无法识别的选择器发送到实例 0xb0000000000002d3'

第四 :

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

=> 同样的例外

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
)
4

1 回答 1

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]如果您没有本地化内容,您可能不需要这样做

于 2017-02-18T13:51:58.597 回答