jQuery.fixture.make  function     

Used to make fixtures for findAll / findOne style requests.

//makes a nested list of messages
$.fixture.make(["messages","message"],1000, function(i, messages){
  return {
    subject: "This is message "+i,
    body: "Here is some text for this message",
    date: Math.floor( new Date().getTime() ),
    parentId : i < 100 ? null : Math.floor(Math.random()*i)
  }
})
//uses the message fixture to return messages limited by offset, limit, order, etc.
$.ajax({
  url: "messages",
  data:{ 
     offset: 100, 
     limit: 50, 
     order: ["date ASC"],
     parentId: 5},
   },
   fixture: "-messages",
   success: function( messages ) {  ... }
});
$.fixture.make(types, count, make, filter) -> undefined
{Array|String}

An array of the fixture names or the singular fixture name. If an array, the first item is the plural fixture name (prefixed with -) and the second item is the singular name. If a string, it's assumed to be the singular fixture name. Make will simply add s to the end of it for the plural name.

{Number}

the number of items to create

{Function}

a function that will return json data representing the object. The make function is called back with the id and the current array of items.

{Function}

(optional) a function used to further filter results. Used for to simulate server params like searchText or startDate. The function should return true if the item passes the filter, false otherwise. For example:

function(item, settings){
          if(settings.data.searchText){
              var regex = new RegExp("^"+settings.data.searchText)
              return regex.test(item.name);
          }
}
{undefined}
© Jupiter IT - JavaScriptMVC Training and Support