Tweak url attachment a bit.

This commit is contained in:
Brad Dunbar
2013-03-11 09:47:11 -04:00
parent c82cca42af
commit 26efd06a21
2 changed files with 21 additions and 14 deletions

View File

@@ -1522,14 +1522,15 @@ var Library = Backbone.Collection.extend({
may be included as an option. Passing <tt>false</tt> as the
comparator option will prevent sorting. If you define an
<b>initialize</b> function, it will be invoked when the collection is
created. The constructor copies following fields from the options into
instance variables: <tt>url</tt>, <tt>model</tt> and <tt>comparator</tt>.
created. There are several options that, if provided, are attached to the
collection directly: <tt>url</tt>, <tt>model</tt> and <tt>comparator</tt>.
</p>
<pre>
var tabs = new TabSet([tab1, tab2, tab3]);
var spaces = new Backbone.Collection([], {
url: "/spaces", model: Space
model: Space,
url: '/spaces'
});
</pre>
@@ -3842,13 +3843,17 @@ ActiveRecord::Base.include_root_in_json = false
<h2 id="changelog">Change Log</h2>
<b class="header">Edge</b> &mdash; <small><i>Unreleased</i></small><br/>
<b class="header">Edge</b> &mdash; <small><i>Unreleased</i></small> &mdash; <a href="https://github.com/documentcloud/backbone/compare/0.9.10...master">Diff</a><br/>
<ul style="margin-top: 5px;">
<li>
The <tt>silent</tt> option has been removed from <tt>Model#set</tt>.
Custom options should be used to accomplish this effect instead.
</li>
<li>
Constructing a new collection with a <tt>url</tt> option will attach it
to the new instance.
</li>
</ul>
<b class="header">0.9.10</b> &mdash; <small><i>Jan. 15, 2013</i></small> &mdash; <a href="https://github.com/documentcloud/backbone/compare/0.9.9...0.9.10">Diff</a><br />

View File

@@ -1049,18 +1049,20 @@ $(document).ready(function() {
collection.add(collection.models, {merge: true}); // don't sort
});
test("Copy known options into instance fields in the constructor", function() {
var model = new Backbone.Model();
var collection = new Backbone.Collection([], { model: model });
equal(collection.model, model);
test("Attach options to collection.", 3, function() {
var url = '/somewhere';
var model = new Backbone.Model;
var comparator = function(){};
var url = "/somewhere";
var collection = new Backbone.Collection([], { url: url });
equal(collection.url, url);
var collection = new Backbone.Collection([], {
url: url,
model: model,
comparator: comparator
});
var comparator = function() {};
var collection = new Backbone.Collection([], { comparator: comparator });
equal(collection.comparator, comparator);
strictEqual(collection.url, url);
ok(collection.model === model);
ok(collection.comparator === comparator);
});
});