Appengine - javascript:如何从web前端删除一个字符串作为键的实体

appengine - javascript: how to delete an entity with string as key from web front end

本文关键字:字符串 一个 实体 javascript 删除 前端 web Appengine      更新时间:2023-09-26

我有以下问题:当我去https://*.appspot.com/_ah/api#p/questionendpoint/v1/questionendpoint.removeQuestion并输入我的字符串id,看起来例如"ahFzfnRyaXZpYWwtcGVyc3VpdHIQCxIIUXVlc3Rpb24Y4toBDA2"一切正常。

如果我从页面调用以下代码,则删除失败。为什么?我做错了什么?我用与上面相同的键调用removeQuestion函数…但它不起作用……req看起来是正确的,并且包含正确的rpcParams(字符串键)。数据保存值为false。我不知道我做错了什么…

var req = gapi.client.questionendpoint.removeQuestion(key);
req.execute(function( data )
{ 
    addInfo(data);
});

端点函数如下所示,正在工作(通过_ah/api/...链接)

@ApiMethod(name = "removeQuestion")
public Question removeQuestion(@Named("id")
String id)
{
    EntityManager mgr = getEntityManager();
    Question question = null;
    try
    {
        question = mgr.find(Question.class, id);
        mgr.remove(question);
    }
    finally
    {
        mgr.close();
    }
    return question;
}

,我的问题类的键定义如下:

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;

好了,现在我知道它是怎么工作的了…

引擎的所有函数似乎都在使用数组…所以只有以下工作(其中key是我的字符串值…)

var data = {};
data['id'] = key; 
var req = gapi.client.questionendpoint.removeQuestion(data);
req.execute(function( data )
{ 
    updateQuestionsTable();
});