1

In this below code

 var productcollection = new Products([this.$results]);
 alert(productcollection.length);

here this.$results holds a string more like this

{"ProdID":"98","ProdName":"product1","ProdPic":"null","ProdGist":"null","ProdDesc":"null","ProdCat":"","ProdTech":"","LastModified":""},{"ProdID":"928","ProdName":"product21","ProdPic":"null","ProdGist":"null","ProdDesc":"null","ProdCat":"","ProdTech":"","LastModified":""}

But the length of the collection is returned as "1" . what correction should i make to the models data that i am giving to the collection . So that it returns "2".

4

1 回答 1

2

If you really have a string in this.$results try this:

var array = JSON.parse('['+this.$results+']');
var productcollection = new Products( array );

Your code was creating an Array containing one large string, like:

new Products( ["text"] );
于 2013-11-15T10:46:50.170 回答