FAQ Database Discussion Community


Can.Model: creating model instances from plain objects

canjs,canjs-model
I have a can.Model with defined findOne, findAll methods. Sometimes however it is required to create model instances from plain objects, e.g. these objects are bootstrapped in html as globals during initial page load. The problem is that these instances are not merged with instances stored in can.Model.store object. Moreover...

CanJS: how to package view templates for production

canjs,canjs-view
What is the optimal way of packaging view templates for production use? I have a number of .stache files. In development they are loaded synchronously with can.view(). In production i want to avoid multiple HTTP requests. What is the right way to do it? Should i bundle them as single...

undefined is not a function in canjs

javascript,ejs,canjs
I am trying to fetch data from the json array using canjs in html file with ejs template engine. But when I load the html file on browser It shows the error that "Undefined is not a function". This is my todo.js var Todo = can.Model({ findall : 'GET/todos', findone...

Uncaught TypeError: Cannot read property 'setup' of undefined in canjs

javascript,jquery,canjs
I am learning canjs. I want to use fixture in my application. I have downloaded can.fixture with can.object because object is a dependency of fixture. When I am loading the below file in browser it shows the following error: todo.html: <html> <head> <title>Canjs </title> </head> <body> <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> <script src='../can.jquery.js'...

can-model cannot getting data from .json file

javascript,json,requirejs,canjs,canjs-model
I am trying to implement MVC using AMD in canjs. For that I am using requirejs. This is my domains.json file: [ "1":{"uid": "1","urls": "domain1.abc.com"}, "2":{"uid": "2","urls": "domain2.abc.com"}, "3":{"uid": "3","urls": "domain3.abc.com"} ] This is my domainModel: define(['can'], function(can){ SearchModel= can.Model({ id: 'uid', findAll: 'GET /domains.json' },{}) return SearchModel; }) This...

Creating a Pagination object with Can.js

javascript,canjs
I'm creating a pagination observable object. I instantiate it with a collection, and it has a derived paginatedList, and sometime later I update it's master list (say I've filtered the data). Obviously I want the derived list to recognize that and re-render the view, but it doesn't. Something must not...

Deferred then of then is undefined for IndexedDb

javascript,jquery,indexeddb,jquery-deferred,canjs
I'm using CanJs and I'm learning jquery deferred but I have a problem. I created a controller as sort of Singleton to manage data in IndexedDb. First of all, I created an openDb function like this: openDbDeferred: null, openDb: function (dbName, dbVersion) { console.log('Open DB...'); var openDbDeferred = this.openDbDeferred; if...

Unexpected token ) in my code

javascript,jquery,ejs,canjs
I am learning canjs and trying to retrive the data. As I am beginner I have wrote my whole code in one file. This is my canjs file: Players = can.Control({ init: function(){ this.element.html(can.view('view/players.ejs',{ players: this.options.players })); } }) Player = can.Model({ findAll: 'GET /players' },{}); var PLAYERS = [...

How can I add a property with a dot in the name to an existing CanJS can.Map?

javascript,canjs
Say I have an existing can.Map called someMap and I need to add a new property named some.data that will contain a string. In vanilla JS, you can do someMap["some.data"] = "someString" \\ Object {some.data: "someString"} There doesn't seem to be a way to do this with a can.Map unless...