关于在Drupal中使用REST Server 增加node时有taxonomy_term 和 node reference的解决方法



node的Data结构如上图,其中field_sample_state是一个taxonomy_term,field_sampletracert 是一个node reference。按着一般情况,直接生成了以下的Json:

  'field_smaple_state':{ 'und':[{'tid':'560'}]},
                                          'field_sampletracert':{'und':[{'target_id':'98533'}]},

但实际post到服务器的时侯,Service不能识别它的结构,造成上传失败,经过网络搜索和多次测试和读文章,发现它的结构与新建字段时的设置有关,并找到下面一句描述:

I found the solution! The required data structure depends on the input widget, since Services uses the form submit handlers (which may be a major design flaw). For "Autocomplete/Tagging" the label (id) thingy is necessary. But if you switch to checkboxes it reads "field_reference": { 1:1, 2:2, ... ,nid:nid} and for select box "field_reference": [1,2,3 ... nid].

The REST-API depends on the widgets the frontend uses ... but at least it works. I guess its upside is that REST-posts are validated just as normal form inputs are. I'll also have a look at the approach implemented http://drupal.org/project/restws

对此,需要对设置改为select list并将json修改为:

  'field_smaple_state':{'und':['560']},
                                          'field_sampletracert':{'und':'129328'},

 经过测试,得到post的正确结果。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值