在嵌套函数中向列表中添加值

时间:2016-02-19 20:42:04

标签: java android list

我无法将值添加到<!-- create a custom component my-form --> <dom-module id="my-form"> <template> <form is="iron-form" id="form" method="post"> <paper-input name="name" label="name" id="name"></paper-input> <paper-button raised on-click="submitForm">Submit</paper-button> </form> </template> <script type="text/javascript"> Polymer({ is: "my-form", submitForm: function() { alert(this.$.name.value); if(this.$.name.value != "") // whatever input check this.$.form.submit(); } }) </script> </dom-module> <my-form></my-form> <!-- use custom-component my-form --> 列表中。

尽管对象检查证明那里有值,但该函数返回一个空列表。我究竟做错了什么?

userInterests

运行中:

 public List getUserInterests(String id){
    final ParseQuery<ParseObject> queryFindAllInterests = ParseQuery.getQuery("Interests");
    final List<String> userInterests = new ArrayList<>();

    queryFindAllInterests.whereEqualTo("user", id);
    queryFindAllInterests.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(final List<ParseObject> interestList, ParseException e) {
            if (e == null) {

                  for (ParseObject object : interestList) {
                        userInterests.add(object.getString("interest"));
                        System.out.println("Object check: " + object);
                   }
            } else {
                  Log.d("interest retrieval", "Error: " + e.getMessage());
            }
        }
    });

    System.out.println("User interests: " + userInterests);
    return userInterests;
}

更新:

所以我把for循环更改为:

I/System.out: User interests: []
I/System.out: Object check: com.parse.ParseObject@132ac47a
I/System.out: Object check: com.parse.ParseObject@216f042b
I/System.out: Object check: com.parse.ParseObject@33cc1088
I/System.out: Object check: com.parse.ParseObject@c1caa21

输出显示正确的字符串:

for (ParseObject object : interestList) {
                        String interest = object.getString("interest");
                        userInterests.add(interest);
                        System.out.println("Object check: " + interest);
                        }

0 个答案:

没有答案