Monday 15 September 2014

javascript - Backbone.js requestPager conditionally exclude paramater from URL -


RequestPager sends requests to server_api as query strings for all attributes. However, sometimes I want to exclude the parameter on some condition. How is it, I'm setting the ultimate:

  server_api: {query: function () {return.searchQuery}, type: function () {return.searchType}}   

If this.searchQuery is empty, then this URL should be ? Query = & amp; Type = 1 . But do not want to send me the query or type when it is empty or when some other situation fails.

I know dirty way:

  if (! MyCollection.searchQuery) {delete (myCollection.server_api.licensed); }   

But this is not practical because because of the text I want to make this function, I am looking for a better way to do this. Any help?

If you see it:

  _ (_.result (self, "server_api"), function (value, key) {if (_.isFunction (value)) {value = _.bind (value, self); value = value ();} queryAttributes [key] ] = Value;});   

You'll see it uses it:

Results _ Result (object, property)

Apply the value of the named property if it is a function; Otherwise, return it.

  var object = {thing: 'cramps', content: function () {return 'nonsense'; }}; _.result (object, 'cheese'); = & Gt; "Cramps" _resrace (object, 'luggage'); = & Gt; "Nonsense"    

This means that you can do a server_api job that gives the right thing.

No comments:

Post a Comment