0

I've been using StackMob's fetch() function to retrieve all objects in my table, given by the fetch() method as a single model object. Each object has multiple attributes with corresponding values. I've then used JSON.stringify(model) to get this output:

{"0":{"attribute1":val1,"attribute2":"val2","attribute3":val3,"attribute4":"val4"},
"1":{"attribute1":val1,"attribute2":"val2","attribute3":val3,"attribute4":"val4"},
"2":{"attribute1":val1,"attribute2":"val2","attribute3":val3,"attribute4":"val4"}

...and so on.

How can I print out just each of those values?

StackMob has a get() function that can be used as such:

var a_book = new Book({ 'title': 'The Complete Calvin and Hobbes', 'author': 'Bill Watterson' });
console.debug(a_book.get('title')); //prints out "The Complete Calvin and Hobbes"

But I'm not sure how I would use it in my situation, where I'm retrieving all of the objects in my table, rather than creating a new object (as above).

4

1 回答 1

0

由于stackmob js sdk是建立在backbonejs上的,你可以声明一个集合,它可以包含你的“表”中的所有“行”,然后遍历集合以对“表”中的每个项目执行你想要的任何操作

var MyModel = StackMob.Model.extend({
        schemaName:'YOUR_SCHEMA_NAME'
    });

var MyCollection= StackMob.Collection.extend({
        model:MyModel
    });

var myCollection = new MyCollection();
myCollection.fetch({async: true});
myCollection.each(function(item){
                    //do something with item, maybe print
               });
于 2013-03-19T15:01:36.947 回答