【问题标题】:How to delete entire row from Parse.com and update it with new data如何从 Parse.com 中删除整行并使用新数据进行更新
【发布时间】:2015-02-18 21:19:54
【问题描述】:

删除代码

            DeleteDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final ParseObject Details = new ParseObject("Details");

                ParseUser user = ParseUser.getCurrentUser();
                Details.put("User", user);

                Details.remove("Age");
                Details.remove("Email_Address");
                Details.remove("Location");
                Details.remove("FullName");

                Details.saveInBackground();

            }
        });

我已经创建了上面的代码,它会从 Parse 上的表中删除数据,但是它会自动创建一个新字段。我希望能够输入数据,将其删除并再次输入。一旦用户退出应用程序并返回到它,数据将从云中获取并显示在 TextViews 中。

TextView 代码

ParseQuery<ParseObject> requestAge = ParseQuery.getQuery("Details");
        requestAge.getFirstInBackground(new GetCallback<ParseObject>() {

            public void done(ParseObject reqDetails, ParseException e) {
                if (reqDetails != null) {
                    Log.d("reqDetails", "Got it");
                    //Retrieve Age
                    String gettheAge = reqDetails.getString("Age");
                    EditText displayAge = (EditText)findViewById(R.id.ageET);
                    displayAge.setText(gettheAge);

                    //Retrieve E-mail address
                    String gettheEmail = reqDetails.getString("Email_Address");
                    EditText displayEmail = (EditText)findViewById(R.id.EmailET);
                    displayEmail.setText(gettheEmail);

                    //Retrieve Location:
                    String gettheLocation = reqDetails.getString("Location");
                    EditText displayLocation = (EditText)findViewById(R.id.LocationET);
                    displayLocation.setText(gettheLocation);

                    //Retrieve Name:
                    String gettheName = reqDetails.getString("FullName");
                    EditText displayName = (EditText)findViewById(R.id.NameET);
                    displayName.setText(gettheName);

                    Toast.makeText(getApplicationContext(),
                            "Successfully Recieved Personal Details",
                            Toast.LENGTH_LONG).show();

                } else {
                    Log.d("reqAge", "Empty_query");


                    Toast.makeText(getApplicationContext(),
                            "Can't Get Details, Check Connection", Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

【问题讨论】:

    标签: android database parse-platform cloud


    【解决方案1】:

    如果要在 Parse 中删除对象,只需在要删除的对象上调用 deleteInBackground 方法即可。

    Android Parse Docs

    【讨论】:

    • 我有,但它只会删除年龄、位置、姓名和电子邮件地址。它不会删除整行。此外,它还创建了一个新行,因此我无法删除数据并再次保存以使其显示在 TextViews 中(如果有意义的话)。
    【解决方案2】:

    这是一个关于如何通过 ID 删除特定行的示例:

    //"Status" is the tableName in parse.com
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
    //"objectId" the column name in parse.com
    //objectID is the content ID in the table objectId
    query.whereEqualTo("objectId", objectID);
    query.getFirstInBackground(new GetCallback<ParseObject>() {
    @Override
    public void done(ParseObject status, ParseException e) {
       try {
             status.delete();
             status.saveInBackground();
           }catch(ParseException ex){
             ex.printStackTrace();
           }
           }
     });
    

    希望这有助于祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 2018-02-20
      • 1970-01-01
      相关资源
      最近更新 更多