Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone collection from Json file and cache on localstorage
    primarykey
    data
    text
    <p>I am relatively new in the backbone library. I'm trying to build a mobile application based on backbone + requirejs + jquery-mobile. I can fill my collection with existing json local file. (in the future may come from a remote server). Now I'm trying to get this collection to be called only once and then storing it in localStorage for read. for this I am trying to use this adapter (<a href="https://github.com/jeromegn/Backbone.localStorage" rel="nofollow">https://github.com/jeromegn/Backbone.localStorage</a>) but I do not understand how.</p> <h2>Sample code</h2> <pre><code>// models define([ 'underscore', 'backbone' ], function(_, Backbone) { var AzModel = Backbone.Model.extend({ defaults: { item: '', img:"img/gi.jpg" }, initialize: function(){ } }); return AzModel; }); // Collection define(['jquery', 'underscore', 'backbone', 'models/az'], function($, _, Backbone, AzModel) { var AzCollection = Backbone.Collection.extend({ localStorage: new Backbone.LocalStorage("AzStore"), // Unique name within your app. url : "json/azlist.json", model : AzModel parse : function(response) { return response; } }); return AzCollection; }); define(['jquery', 'underscore', 'backbone', 'collections/azlist', 'text!templates/karate/az.html'], function($, _, Backbone, AzList, AzViewTemplate) { var AzView = Backbone.View.extend({ id:"az", initialize: function() { this.collection = new AzList(); var self = this; this.collection.fetch().done(function() { //alert("done") self.render(); }); }, render : function() { var data = this.collection; if (data.length == 0) { // Show's the jQuery Mobile loading icon $.mobile.loading("show"); } else { $.mobile.loading("hide"); console.log(data.toJSON()); this.$el.html(_.template(AzViewTemplate, {data:data.toJSON()})); // create jqueryui $(document).trigger("create"); } return this; } }); return AzView; }); </code></pre> <p>Does someone can point me the way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload