在Android中使用Loopback.js更新行

时间:2017-04-05 21:15:42

标签: android node.js loopbackjs

我为我的Android应用程序创建了一个带有loopback(Node.js)的restful api。 我可以使用findByIddestroy等。但是当我尝试更新我的数据时,只需为first_name工作。 我该如何解决这个问题?

我的代码: 的 MainActivity

 public void guncelle(View view) {
    repository.findById(user_id.getText(), new ModelRepository.FindCallback<Users>() {
        @Override
        public void onSuccess(Users user) {
            if (user == null) {
                Toast.makeText(getApplicationContext(), "Hata oluştu!", Toast.LENGTH_SHORT).show();
            } else {
              user.put("first_name", first_name.getText()); //This is work
              user.put("last_name", last_name.getText()); // nope
          user.put("email", email.getText()); //nope
               user.put("username", username.getText()); // and nope :(

                user.save(new VoidCallback() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(getApplicationContext(), "Güncelleme Başarılı", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable t) {
                        Toast.makeText(getApplicationContext(), "Hata oluştu!", Toast.LENGTH_SHORT).show();
                        Log.d("Hata: ", String.valueOf(t));
                    }
                });
            }
        }

        @Override
        public void onError(Throwable t) {
            Toast.makeText(getApplicationContext(), "Hata oluştu!", Toast.LENGTH_SHORT).show();
            Log.d("Hata: ", String.valueOf(t));
        }

    });
}

用户

public class Users extends Model {

private String first_name, last_name, email, username;

public void setFirst_Name(String first_name) {
    this.first_name = first_name;
}

public String getFirst_Name() {
    return first_name;
}

public void setLast_name(String last_name) {
    this.last_name = last_name;
}

public String getLast_name() {
    return last_name;
}

public void setEmail(String email) {
    this.email = email;
}

public String getEmail() {
    return email;
}

public void setUsername(String username) {
    this.username = username;
}

public String getUsername() {
    return username;
} }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我在github中使用旧代码,但新代码正在使用。

        Users user= repository.createObject(ImmutableMap.of("id", 2));
    user.setFirst_name("Name");
    user.setLast_name("Surname");
    user.setEmail("Email");
    user.setUsername("Username");
    user.save(new VoidCallback() {
        @Override
        public void onSuccess() {
            // Pencil now exists on the server!
        }

        @Override
        public void onError(Throwable t) {
            // save failed, handle the error
        }
    });