javascript - Adding more, another loop to my Underscore template with a new backbone model? -


update :

i have got code working, of sorts, have 2 issues , 1 problem not sure how fix. post current code below. 1 clients append right section within timesheetdata template. wraps option tag within clientdata template within option .

so :

 <select>      <option> <option value="xx"> xxx </option> </option>  </select> 

now know designed do, have root element can not seem find solution issue, although still works.

now other issue need select default client, loaded timesheet model, timesheetrow.client_id holds database saved row. not sure how access in if statement or other way within client template.

now problem have client data not load? when reload / refresh page lists clients in option tags, loads nothing, giving me empty select tag. when not load anything, don't have console log errors or anything?

all welcome :)

so current backbone code:

client data code :

var clientmodel = backbone.model.extend({     defaults: {         client: "",     } }); //end of clientmodel  var clientcollection = backbone.collection.extend({     model: clientmodel,     url: '/dashboard/json/clients' }); //end of clientcollection  var clientview = backbone.view.extend({     tagname: 'option',     template: _.template($('#clientdata').html()),      render: function() {         this.$el.append(this.template(this.model.tojson()));         return this.$el;     } });  

timesheet data code :

var timesheetmodel = backbone.model.extend({     defaults: {         timesheetrow: "",     } }); //end of timesheetmodel  var timesheetcollection = backbone.collection.extend({     model: timesheetmodel,     url: '/dashboard/json/row/' + timesheetid() }); //end of timesheetcollection  var timesheetrowview = backbone.view.extend({     classname: 'timesheetrowline',      template: _.template($('#timesheetdata').html()),      render: function() {         this.$el.append(this.template(this.model.tojson()));         return this.$el;     } }); //end of timesheetrowview 

timesheet & client code section:

var timesheetcollectionview = backbone.view.extend({     el:'#mastercontainer',       template: _.template($('#timesheetform').html()),      events: {         "click .actionsubmit": "handlesubmit"     },       initialize: function() {         //get client data & add template         this.clientcollection = new clientcollection();         this.listento(this.clientcollection, "add", this.addclient);         this.clientcollection.fetch();          //get main timesheet data & add template         this.collection = new timesheetcollection();         this.listento(this.collection, "add", this.addtimesheetrow);         this.collection.fetch();          this.$el.append(this.template());         this.submitbutton = this.$(".actionsubmit");     },      addtimesheetrow: function(model) {         var view = new timesheetrowview({model: model});         view.render().insertbefore(this.submitbutton);     },      addclient: function(model) {         var clients = new clientview({model: model});         $("#timesheetdatalist .timesheetrowline #clienttemp").append( clients.render() );     },      handlesubmit: function(){         //in real life, validate , save model         alert("form submit");         return false;     } }); //end of timesheetcollectionview  var collectionview = new timesheetcollectionview();  

this underscore template code:

 <script type="text/template" id="timesheetform">     <form action="#" method="post" id="timesheetdatalist" style="width: auto; padding-left: 50px;">           <input type="submit" class="actionsubmit" value="send"/>     </form>  </script>   <script type="text/template" id="timesheetdata">     <%= console.log( timesheetrow.client_id ) %>     <input type="hidden" name="data[timesheetrow][<%= timesheetrow.id %>][id]" value="<%= timesheetrow.id  %>">    <input type="type" name="data[timesheetrow][<%= timesheetrow.id %>][jobtitle]" value="<%= timesheetrow.twistjob  %>">      <select name="data[timesheetrow][<%= timesheetrow.id %>][client_id]" id="clienttemp"></select>   </script>   <script type="text/template" id="clientdata">     <option value="<%= client.id %>"><%= client.clientname %></option>  </script> 

old post


ok, having issue backbone view rendering underscore template, again. thought best ask new question.

my last question, underscore template looping, without loop?, guy on there me trying, little success edit code , extend little more.

code remove - see update 

so trying follow same methods. know have more training expand knowledge.

with code, have list of clients, need load select / option pull down form element. seems loop around 17 times, number of rows have in timesheet. console logging 'client' in 'clientdata' template, displays client data client data logged in timesheet rows, not clients json data model / collection pointing to? getting ref. error client? though in model default?

i understanding backbone (a bit), not underscore much.

all welcome.

thanks,


:: edit ::

i thought post underscore templates.

 code removed - see update 

so trying loop around in clientdata template clients, 'option' tags, add select elements on timesheetdata template. complete template being added timesheetform template, does.

this might need different method , might have been fault don't work forgot explain on other question out client list.

thanks,


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -