<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techy Things &#187; backbone</title>
	<atom:link href="https://tech.yipp.ca/category/backbone/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech.yipp.ca</link>
	<description>Just another Yipp.ca Blogs site</description>
	<lastBuildDate>Thu, 01 May 2025 18:06:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Backbone Collection Flexible Value Sorting Solution</title>
		<link>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-collection-custom-sorting-solution</link>
		<comments>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/#comments</comments>
		<pubDate>Mon, 18 Jun 2018 19:03:33 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=3103</guid>
		<description><![CDATA[<p>Model/Collection Declaration Inputs.Collection = Backbone.Collection.extend({ model: Inputs.Model, url: "/apis/v2/inputs", sortAttribute: "name", // supported attributes are model's element names + any custom strategies below comparator: function(model) { return Utils.genericComparator.call(this, model); }, strategies: {}, changeSort: function&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/">Backbone Collection Flexible Value Sorting Solution</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Model/Collection Declaration</h2>
<pre> Inputs.Collection = Backbone.Collection.extend({
   model: Inputs.Model,
   url: "/apis/v2/inputs",
   sortAttribute: "name", // supported attributes are model's element names + any custom strategies below
   comparator: function(model) 
   {
     return Utils.genericComparator.call(this, model);
   },
   strategies: {},
   changeSort: function (sortAttribute) 
   {
     if (this.strategies[sortAttribute]) {
       this.comparator = this.strategies[sortAttribute];
       return;
     }
     this.comparator = Inputs.Collection.prototype.comparator;
     this.sortAttribute = sortAttribute;
   },
   parse: function (resp)
   {
     var data = ( resp &amp;&amp; resp.input_list ) ? resp.input_list : [];
     return data;
   }
 });
</pre>
<h2>Initialization of Sort Method in View</h2>
<pre> initialize: function () // View Initialize
 {
   var self = this;
   this.collection = new Inputs.Collection();
   var currentMethod = app.storageModel.load("inputs:sort");
   if (currentMethod) {
     this.collection.changeSort(currentMethod);
   } else {
     app.storageModel.save("inputs:sort", this.collection.sortAttribute);
   }
   ...
 },
 afterRender: function() 
 {
   // Indicate to user what we are sorting
   var currentMethod = this.collection.sortAttribute;
   if (currentMethod &amp;&amp; currentMethod.match(/_r$/)) {
     // reserve sorting
     this.$(".jsSort[data-sort=\""+currentMethod.replace(/_r$/,"")+"\"]").addClass("down");
   } else {
     this.$(".jsSort[data-sort=\""+currentMethod+"\"]").addClass("up");
   }
 },
</pre>
<h2>Dynamic Code to Change Sort Method</h2>
<pre> events: {
   "click .jsSort": "sortTable"
 },
 sortTable: function(e) 
 {
   var sortBy = $(e.currentTarget).data("sort");
   var currentMethod = app.storageModel.load("inputs:sort");
   if (sortBy === currentMethod) {
     sortBy += "_r"; // reserve sorting
   }
   this.collection.changeSort(sortBy);
   this.collection.sort();
   app.storageModel.save("inputs:sort", sortBy);
   this.render();
 },
</pre>
<h2>Html Code</h2>
<pre>&lt;div class="span4 sort jsSort unselectable" data-sort="name"&gt;Name&lt;/div&gt;
&lt;div class="span5 sort jsSort unselectable" data-sort="url"&gt;Connection&lt;/div&gt;
&lt;div class="span2 sort jsSort unselectable" data-sort="state"&gt;Status&lt;/div
</pre>
<h2>Generic Sort Code</h2>
<pre> // Comparator Function for Collection sort
 //
 // Usage: 
 // My.Collection = Backbone.Collection.extend({
 // sortAttribute: "name", // supported attributes are model's element names + any custom strategies below
 // comparator: function(model) { return Utils.genericComparator.call(this, model); },
 // strategies: { &lt;your own custom strategy not covered by genericComparator&gt; },
 // changeSort: function (sortAttribute) {
 // if (this.strategies[sortAttribute]) {
 // this.comparator = this.strategies[sortAttribute];
 // return;
 // }
 // this.comparator = My.Collection.prototype.comparator;
 // this.sortAttribute = sortAttribute;
 // },
 // ...
 // });
 Utils.genericComparator = function (model) 
 {
   var last = this.sortAttribute.slice(-2); // last 3 chars
   var reversed = false;
   var attribute = this.sortAttribute;
   if (last === "_r") {
     attribute = this.sortAttribute.substr(0, this.sortAttribute.length-2);
     reversed = true;
   }
 
   var value = model.get(attribute);
   var matches;
   if (matches = attribute.match(/\((.*)\)$/)) // ends with () ?
   { 
     // function call
     var fname = attribute.substring(0, attribute.length - matches[0].length);
     if (fname.indexOf(".") &gt; 0) 
     { 
       var flist = fname.split(".");
       var args = matches[1].replace(/'/g, "");
       if (flist.length == 2) 
       {
         value = model[flist[0]][flist[1]](args);
       }
     } else {
       value = model[fname](matches[1]);
     }
   } 
   var retval = Utils.genericComparatorFromValue(value, reversed);
   return retval;
 };
 
 // Takes a value as input format it for consistant compare and optionally reverse it
 // Returns value prepped for compare
 Utils.genericComparatorFromValue = function (value, reversed) { 
   if (_.isUndefined(value)) {
     return value;
   }
 
   if (typeof value.toLowerCase === "function") {
     // string type 
     var string = value.toLowerCase();
     if (reversed) {
       string = string.split(""); // string to array
       string = _.map(string, function(letter) { return String.fromCharCode(-(letter.charCodeAt(0))); });
       return string;
     }
     return string;
   } else if (value === true || value === false) {
     // boolean type
     return reversed ? !value : value;
   } else if (value === null) {
     return value;
   } else {
     // integer, float
     return reversed ? -value : value;
   }
 };

</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/">Backbone Collection Flexible Value Sorting Solution</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone bootstrap model validations</title>
		<link>https://tech.yipp.ca/backbone/backbone-bootstrap-model-validations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-bootstrap-model-validations</link>
		<comments>https://tech.yipp.ca/backbone/backbone-bootstrap-model-validations/#comments</comments>
		<pubDate>Wed, 16 Aug 2017 16:04:13 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2856</guid>
		<description><![CDATA[<p>Scenario We have fields that needs to be validated. We already highlight the erroneous field(s) and display a specific message below each erroneous field. Now we want to display a popup notification on the&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-bootstrap-model-validations/">Backbone bootstrap model validations</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>Scenario</h3>
<p>We have fields that needs to be validated. We already highlight the erroneous field(s) and display a specific message below each erroneous field. Now we want to display a popup notification on the top of page.</p>
<h3><img class="alignnone size-medium wp-image-2857" src="http://tech.yipp.ca/files/2017/08/bootstrap-validations-example-400x160.png" alt="bootstrap-validations-example" width="400" height="160" /></h3>
<h3></h3>
<h3>Solution #1 - Invite to look below for actual error(s)</h3>
<p><a href="http://tech.yipp.ca/files/2017/08/bootstrap-validations-generic-message.png"><img class="alignnone size-medium wp-image-2859" src="http://tech.yipp.ca/files/2017/08/bootstrap-validations-generic-message-400x93.png" alt="bootstrap-validations-generic-message" width="400" height="93" /></a></p>
<pre>var isValid = this.model.save(settings, {
   wait: true,
   success: function(model) {
      callback(model);
      var url = "/streams/" + model.get('id');
      app.router.navigate(url, {trigger: false});
      self.render();
   },
   error: function()
   {
      notifier.error_x("Please correct the field(s) marked in red below.");
      self.updateApplyButton();
   }
});
      
if (isValid === false)
{	
   // validation error
   self.updateApplyButton();
}
</pre>
<h3>Solution #2 - Display the actual error(s)</h3>
<p><a href="http://tech.yipp.ca/files/2017/08/bootstrap-validations-actual-error.png"><img class="alignnone size-medium wp-image-2858" src="http://tech.yipp.ca/files/2017/08/bootstrap-validations-actual-error-400x93.png" alt="bootstrap-validations-actual-error" width="400" height="93" /></a></p>
<pre>var isValid = this.model.save(settings, {
   wait: true,
   success: function(model) {
      callback(model);
      var url = "/streams/" + model.get('id');
      app.router.navigate(url, {trigger: false});
      self.render();
   },
   error: function()
   {
      self.updateApplyButton();
   }
});
      
if (isValid === false)
{	
   // validation error
   for (var key in this.model.validationError)
   {  if (this.model.validationError.hasOwnProperty(key))
      {  notifier.error_x(this.model.validationError[key]);
      }
   }

   self.updateApplyButton();
}
</pre>
<h3>Discussion</h3>
<p>The solution #1 is preferred because it directly tells the user to look below and secondly since it auto-fades after some time, it better not contain too complex instructions.</p>
<p>Also notice the <em>isValid</em> variable. It is actually a returned promise. But it happens to be <em>null</em> when there is validation error(s) so it can be evaluated as a boolean although it is not a solid as it could be.</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-bootstrap-model-validations/">Backbone bootstrap model validations</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-bootstrap-model-validations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone after all render</title>
		<link>https://tech.yipp.ca/backbone/backbone-render/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-render</link>
		<comments>https://tech.yipp.ca/backbone/backbone-render/#comments</comments>
		<pubDate>Fri, 27 Jan 2017 18:27:52 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2724</guid>
		<description><![CDATA[<p>views["#content-view"].render().once("afterRender", function() { // console.log("rendered"); $(window).trigger('scroll.rpinnable'); }, this);</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-render/">Backbone after all render</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>views["#content-view"].render().once("afterRender", function() {<br />
// console.log("rendered");<br />
$(window).trigger('scroll.rpinnable');<br />
}, this);</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-render/">Backbone after all render</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-render/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Callback after all child views have rendered</title>
		<link>https://tech.yipp.ca/backbone/callback-child-views-rendered/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=callback-child-views-rendered</link>
		<comments>https://tech.yipp.ca/backbone/callback-child-views-rendered/#comments</comments>
		<pubDate>Wed, 26 Oct 2016 20:27:53 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2638</guid>
		<description><![CDATA[<p>This is something that has troubled me for long time. Whenever the parent's view afterRender() fired, the child views had not yet rendered. Thus it seemed impossible to know when all child views had&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/callback-child-views-rendered/">Callback after all child views have rendered</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is something that has troubled me for long time. Whenever the parent's view afterRender() fired, the child views had not yet rendered. Thus it seemed impossible to know when all child views had completed to render.</p>
<h3>The solution is</h3>
<pre> var views = {...};
 app.mainView.setViews(views);
 views["#content-view"].render()<strong>.once("afterRender", function() {</strong>
<strong>   // console.log("rendered");</strong>
<strong>   $(window).trigger('scroll.rpinnable');</strong>
<strong> }, this);

</strong></pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/callback-child-views-rendered/">Callback after all child views have rendered</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/callback-child-views-rendered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone create sends PUT /api/presets/undefined instead of POST /api/presets</title>
		<link>https://tech.yipp.ca/backbone/backbone-create-sends-put-undefined-instead-post/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-create-sends-put-undefined-instead-post</link>
		<comments>https://tech.yipp.ca/backbone/backbone-create-sends-put-undefined-instead-post/#comments</comments>
		<pubDate>Mon, 18 Jan 2016 16:49:42 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2204</guid>
		<description><![CDATA[<p>I'm porting code written for Backbone 1.0.0 to a new app using Backbone 1.1.2 and I noticed that isNew() seems broken for objects using custom idAttributes. We are using model.save(settings, {wait:true}) and the Model is configured&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-create-sends-put-undefined-instead-post/">Backbone create sends PUT /api/presets/undefined instead of POST /api/presets</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>I'm porting code written for Backbone 1.0.0 to a new app using Backbone 1.1.2 and I noticed that <strong>isNew()</strong> seems broken for objects using custom idAttributes.</p>
<p>We are using <strong>model.save</strong>(settings, {wait:true}) and the <strong>Model</strong> is configured with <strong>idAttribute</strong>: "name" :</p>
<p><a href="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing.png"><img class="alignnone size-full wp-image-2206" src="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing-s2et.png" alt="backbone-isNew-failing-s2et" width="1022" height="257" /></a></p>
<p>&nbsp;</p>
<p>Backbone 1.1.2 wrongfully sends the request to <strong>PUT /api/presets/undefined</strong>.<br />
Before it was going to <span style="color: #000000;"><strong>POST /api/presets/.</strong></span></p>
<p>Our device's presets map to <strong>filenames</strong> in a directory and they don't have ID the web interfaces uses the <span style="color: #000000;"><strong>name </strong></span>as ID for this model.</p>
<p><a href="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing.png"><img class="alignnone size-full wp-image-2205" src="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing.png" alt="backbone-isNew-failing" width="1022" height="257" /></a></p>
<p>In Backbone 1.0.0, the same code was causing <strong>isNew()</strong> to return <strong>true:</strong></p>
<p><a href="http://tech.yipp.ca/files/2016/01/backbone-isNew-success-old-version.png"><img class="alignnone size-full wp-image-2208" src="http://tech.yipp.ca/files/2016/01/backbone-isNew-success-old-version.png" alt="backbone-isNew-success-old-version" width="1022" height="257" /></a></p>
<p>This is our <strong>save()</strong> call. I inspected that the model does <strong>not</strong> have <strong>name</strong> in it's attributes and is passed a new one via <strong>settings</strong>:</p>
<p><a href="http://tech.yipp.ca/files/2016/01/backbone-isNew-object-befor.png"><img class="alignnone size-full wp-image-2209" src="http://tech.yipp.ca/files/2016/01/backbone-isNew-object-befor.png" alt="backbone-isNew-object-befor" width="1022" height="241" /></a></p>
<p><strong><br />
This could be the commit that broke this :</strong></p>
<p><a href="https://github.com/jashkenas/backbone/commit/11cc0e863f9951b4242144d65b581348bd9ee092" target="_blank">https://github.com/jashkenas/backbone/commit/11cc0e863f9951b4242144d65b581348bd9ee092</a></p>
<p><strong>I tried to patch this commit but it does not resolves it:</strong></p>
<p><a href="https://github.com/jashkenas/backbone/commit/9f81d980f0599e8691af80034944d4abafb3f44b" target="_blank">https://github.com/jashkenas/backbone/commit/9f81d980f0599e8691af80034944d4abafb3f44b</a></p>
<p>So I continue investigating why<strong> isNew()</strong> walks on an object that has <strong>"name"</strong> set in the model and it is because of this line and that <strong>wait</strong> is true :</p>
<p><a href="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing-where-attributes-are-sett.png"><img class="alignnone size-full wp-image-2214" src="http://tech.yipp.ca/files/2016/01/backbone-isNew-failing-where-attributes-are-sett.png" alt="backbone-isNew-failing-where-attributes-are-sett" width="1022" height="241" /></a></p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-create-sends-put-undefined-instead-post/">Backbone create sends PUT /api/presets/undefined instead of POST /api/presets</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-create-sends-put-undefined-instead-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone LayoutManager view not rendering</title>
		<link>https://tech.yipp.ca/backbone/backbone-layoutmanager-view-rendering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-layoutmanager-view-rendering</link>
		<comments>https://tech.yipp.ca/backbone/backbone-layoutmanager-view-rendering/#comments</comments>
		<pubDate>Fri, 23 Oct 2015 02:39:48 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2032</guid>
		<description><![CDATA[<p>Troubleshooting #1 - Did everything load in the network debugger window ? Missing one or several template views could cause the whole UI not to render #2 - Any Javascript errors in Console ?&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-layoutmanager-view-rendering/">Backbone LayoutManager view not rendering</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Troubleshooting</p>
<p>#1 - Did everything load in the network debugger window ?</p>
<p>Missing one or several template views could cause the whole UI not to render</p>
<p>#2 - Any Javascript errors in Console ?</p>
<p>Yes: Is it "context is undefined"? This means it could not found its anchor point on the DOM.</p>
<pre><a href="http://tech.yipp.ca/files/2015/10/layoutmanager-backbone-cons.png"><img class=" size-full wp-image-2035 aligncenter" src="http://tech.yipp.ca/files/2015/10/layoutmanager-backbone-cons.png" alt="layoutmanager-backbone-cons" width="478" height="35" /></a></pre>
<p>One reason could be mismatch of ID in the HTML and Javascript</p>
<p>Watch out what is your root element ID you are attaching too with code like this:</p>
<pre>      // Create a new Layout with options.
      var layout = new Backbone.Layout(_.extend({
        el: "#backbone-container"
      }, options));

</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-layoutmanager-view-rendering/">Backbone LayoutManager view not rendering</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-layoutmanager-view-rendering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone model.save does not trigger error or success callback</title>
		<link>https://tech.yipp.ca/backbone/backbone-model-save-trigger-error-success-callback/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-model-save-trigger-error-success-callback</link>
		<comments>https://tech.yipp.ca/backbone/backbone-model-save-trigger-error-success-callback/#comments</comments>
		<pubDate>Wed, 20 May 2015 13:28:40 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=1764</guid>
		<description><![CDATA[<p>This is a typical error that happens often so I'm writing it down. Anyone can spot the error in this code ? : var deferred = $.Deferred(); recording.save( { success : function () {&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-model-save-trigger-error-success-callback/">Backbone model.save does not trigger error or success callback</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is a typical error that happens often so I'm writing it down.<br />
Anyone can spot the error in this code ? :</p>
<pre>
var deferred = $.Deferred();
 recording.save(
 {
 success : function () { 
 deferred.done();
 }, 
 error : function () { 
 deferred.done();
 }
 });</pre>
<p>The problem is that the first parameter to save is an object of new member's values and not the options. So you need to add either null or {}.</p>
<pre>
var deferred = $.Deferred();
 recording.save(<strong>{}</strong>, 
 {
 success : function () { 
 deferred.done();
 }, 
 error : function () { 
 deferred.done();
 }
 });</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-model-save-trigger-error-success-callback/">Backbone model.save does not trigger error or success callback</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-model-save-trigger-error-success-callback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add GET parameter to a backbone fetch model</title>
		<link>https://tech.yipp.ca/backbone/add-get-parameter-backbone-fetch-model/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-get-parameter-backbone-fetch-model</link>
		<comments>https://tech.yipp.ca/backbone/add-get-parameter-backbone-fetch-model/#comments</comments>
		<pubDate>Thu, 14 May 2015 12:21:00 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=1752</guid>
		<description><![CDATA[<p>Fetch model with GET parameters in URL The solution is to add data: $.param({ mySuperVariableName: 1}) in the fetch options. Folders.data.fetch( { data: $.param({ showContent: 1}), success:function(model, response, options) { //model.deferred.resolve(); }, error:function(model, response, options) {&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/add-get-parameter-backbone-fetch-model/">Add GET parameter to a backbone fetch model</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Fetch model with GET parameters in URL</h2>
<p>The solution is to add <strong>data: $.param({ mySuperVariableName: 1})</strong> in the fetch options.</p>
<pre>Folders.data.fetch(
{
 <strong><span style="color: #008000;">data: $.param({ showContent: 1}),</span></strong>
 success:function(model, response, options)
 {
    //model.deferred.resolve();
 },
 error:function(model, response, options)
 {
    //model.deferred.reject();
 }
});</pre>
<p class="p1">
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/add-get-parameter-backbone-fetch-model/">Add GET parameter to a backbone fetch model</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/add-get-parameter-backbone-fetch-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why my Backbone collection fetch returns only one item</title>
		<link>https://tech.yipp.ca/backbone/backbone-collection-fetch-returns-one-item/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-collection-fetch-returns-one-item</link>
		<comments>https://tech.yipp.ca/backbone/backbone-collection-fetch-returns-one-item/#comments</comments>
		<pubDate>Tue, 12 May 2015 11:41:43 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=1747</guid>
		<description><![CDATA[<p>Step by steps - Use Fildder to inspect network traffic, make sure of what is returned by the server has multiple objects. - Make sure that your IDs are unique - If you override&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-fetch-returns-one-item/">Why my Backbone collection fetch returns only one item</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Step by steps</p>
<p>- Use Fildder to inspect network traffic, make sure of what is returned by the server has multiple objects.</p>
<p>- Make sure that your IDs are unique</p>
<p>- If you override the base model idAttribute, make sure that all items have a distinct attribute for the one marked as the ID by idAttribute. In the following example, if two item had the same name, only one of them would show up :</p>
<pre>Export.Model = Backbone.Model.extend(
{
  urlRoot: "/apis/destinations",
  selected: false,
  idAttribute: "name",
  (...)</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-fetch-returns-one-item/">Why my Backbone collection fetch returns only one item</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-collection-fetch-returns-one-item/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uncaught TypeError: this._ensureElement is not a function</title>
		<link>https://tech.yipp.ca/backbone/uncaught-typeerror-_ensureelement-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uncaught-typeerror-_ensureelement-function</link>
		<comments>https://tech.yipp.ca/backbone/uncaught-typeerror-_ensureelement-function/#comments</comments>
		<pubDate>Tue, 12 May 2015 00:51:54 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=1744</guid>
		<description><![CDATA[<p>Solution: You forgot to add new in front of the backbone view: self.insertView("#destinations-list", new ExportDestinations.Views.Row({model: model}));</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/uncaught-typeerror-_ensureelement-function/">Uncaught TypeError: this._ensureElement is not a function</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Solution: You forgot to add new in front of the backbone view:</p>
<pre>self.insertView("#destinations-list", <strong><span style="color: #339966;">new</span></strong> ExportDestinations.Views.Row({model: model}));</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/uncaught-typeerror-_ensureelement-function/">Uncaught TypeError: this._ensureElement is not a function</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/uncaught-typeerror-_ensureelement-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
