what's wrong in fetch data from collection using ajax source

Hi all,
i create a custom collection with ajax source to fetch data from server and binding to view, but cannot working, please help me.

Collection:
new enyo.AjaxSource({name:'source'});<br /><br />enyo.kind({<br /> name:'clip.GroupCollection',<br /> kind:'enyo.Collection',<br /> source:'source',<br /> model:"clip.VideoModel",<br /> published: {<br /> category: null,<br /> },<br /> categoryChanged: function() {<br /> this.empty({destroy:true});<br /> if(this.category =='home') {<br /> return this.fetch();<br /> }<br /> },<br /> options: { parse: true },<br /> parse: function(data) {<br /> return data && data.result;<br /> },<br /> getUrl: function() {<br /> return "http://api.xxx.vn/app/home/get_groups?id=" + this.get("userid");<br /> }<br />});

View:

enyo.kind({<br /> name:'clip.HomeContent',<br /> kind:'FittableRows',<br /> fit:true,<br /> spotlight:'container',<br /> components:[<br /> {<br /> kind:'moon.Button',content:'click',ontap:'tapped'<br /> },<br /> {<br /> name:'clipNewest',<br /> kind:'clip.ItemHome',<br /> }<br /> ],<br /> create:function(){<br /> this.inherited(arguments);<br /> this.set('collection',new clip.GroupCollection());<br /> },<br /> bindings:[<br /> {<br /> from:"collection",<br /> to:"$.clipNewest.model",<br /> transform:function(data){<br /> console.log('transform data',this.collection);<br /> if(this.collection && this.collection.length>0 && this.collection.at(0)){<br /> console.log('newest',this.collection.at(0));<br /> return this.collection.at(0);<br /> }<br /> }<br /> }<br /> ],<br /> tapped:function(){<br /> console.log('tap');<br /> this.collection.set('category','home');<br /> }<br />});

what's happen when i click detail collection in console log, before show detail, length=0, models=0, but click show detail length=4, models=array(4)
link image: http://postimg.org/image/pajub3dcx/
image

Comments

  • You are binding from collection rather than collection status or collection length or collection models. Once you set the collection, it does not change, even after fetch , since it is the same object in memory. Would recommend passing in a success handler to fetch or using something bound to status to trigger your update.
  • many thanks @psarin
    i change binding by collection length and working now.
    bindings:[<br /> {<br /> from:"collection.length",<br /> to:"$.clipNewest.model",<br /> transform:function(data){<br /> console.log('transform data',this.collection);<br /> if(this.collection && this.collection.length>0 && this.collection.at(0)){<br /> console.log('newest',this.collection.at(0));<br /> return this.collection.at(0);<br /> }<br /> }<br /> },<br /> ]
Sign In or Register to comment.