compile views in controller

73 views
Skip to first unread message

arief nur andono

unread,
Jan 29, 2014, 10:29:02 AM1/29/14
to tot...@googlegroups.com
how to compile views in controller without create views

I store some part of views in database, can I compile it with condition inside in controllers??

Peter Širka

unread,
Jan 29, 2014, 12:26:45 PM1/29/14
to tot...@googlegroups.com
You can use:

self.repository.name = 'Arief';
self.view('<div>@{repository.name} and model @{model.name}</div>', { name: 'total.js' });

Thanks :-)

arief nur andono

unread,
Jan 29, 2014, 1:32:26 PM1/29/14
to tot...@googlegroups.com
I just didn't find in examples..thank you..

arief nur andono

unread,
Jan 29, 2014, 5:08:15 PM1/29/14
to tot...@googlegroups.com
in helpers I create a new function, but self.model return undefined..

framework.helpers.push = function() { 
var self = this;
console.log(self.model);
}

Peter Širka

unread,
Jan 29, 2014, 5:12:22 PM1/29/14
to tot...@googlegroups.com
Hi Arief,
you are using unpublished version from GitHub? I updated this functionality, try to use self.$model ... because I added new feature: components.

arief nur andono

unread,
Jan 29, 2014, 10:57:52 PM1/29/14
to tot...@googlegroups.com
I just npm install partial.js in examples folder

arief nur andono

unread,
Jan 29, 2014, 10:59:44 PM1/29/14
to tot...@googlegroups.com
I tried to run component examples but got this error
undefined:2
framework.component('grid').configure({ class: 'grid' });
          ^
TypeError: Object #<EventEmitter> has no method 'component'
    at eval (eval at <anonymous> (/home/arief/node_modules/total.js/index.js:1:12553), <anonymous>:2:11)
    at /home/arief/node_modules/total.js/index.js:1:12464
    at Array.forEach (native)
    at EventEmitter.Framework.install (/home/arief/node_modules/total.js/index.js:1:12384)
    at EventEmitter.Framework.init (/home/arief/node_modules/total.js/index.js:2:12811)
    at EventEmitter.Framework.run (/home/arief/node_modules/total.js/index.js:2:14553)
    at Object.<anonymous> (/home/arief/web/examples-master/components/index.js:5:11)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

arief nur andono

unread,
Jan 29, 2014, 11:02:47 PM1/29/14
to tot...@googlegroups.com
I thought component really near with template view..

Peter Širka

unread,
Jan 30, 2014, 3:30:46 AM1/30/14
to tot...@googlegroups.com
Yes, it will be similar.
Download a new version from GitHub.

This week I'll publish new version.
Thanks.

arief nur andono

unread,
Jan 30, 2014, 5:23:21 AM1/30/14
to tot...@googlegroups.com
can't wait for it..

I got problem when there is enter in template in controller
like this 

self.view('<div>@{repository.name} and 
model @{model.name}</div>', { name: 'total.js' });

how to compress it before put in self.view function?

Peter Širka

unread,
Jan 30, 2014, 5:55:04 AM1/30/14
to tot...@googlegroups.com
Please describe me more.
You need insert a "template" into the view or ...?

Thanks!

arief nur andono

unread,
Jan 31, 2014, 11:30:30 AM1/31/14
to tot...@googlegroups.com
I'm sorry I made mistake...app send and store enter as \n not enter like I did..

total.js handle \n well..

not it's only utils.js problem..I need to store some views value in array before join it..secod view..
actually I try to make user generated query string so user can put condition by themself..


arief nur andono

unread,
Jan 31, 2014, 12:08:31 PM1/31/14
to tot...@googlegroups.com
I've updated with 1.1.0 and it works well..thank you

this is my utils

framework.helpers.push = function(wherecondition,output) {
if (!self.model.wherearray){
self.model.wherearray = wherecondition;
}else{
self.model.wherearray.push(wherecondition.join(" "));
}

if(output){
self.model.wherearray[0]="where";
return self.model.wherearray.join(" ");
}
};

Peter Širka

unread,
Jan 31, 2014, 12:14:07 PM1/31/14
to tot...@googlegroups.com
Arief is there problem. I had to rename self.model to self.$model (because framework models). Currently: self.model === function, self.$model === object (view model).
framework.helpers.push = function(wherecondition,output) {
    if (!self.$model.wherearray){
        self.$model.wherearray = wherecondition;
    }else{
        self.$model.wherearray.push(wherecondition.join(" "));
    }

    if(output){
        self.$model.wherearray[0]="where";
        return self.$model.wherearray.join(" "); 
    }
};

arief nur andono

unread,
Jan 31, 2014, 6:27:38 PM1/31/14
to tot...@googlegroups.com
use $model return this error

TypeError: Cannot read property 'wherearray' of undefined TypeError: Cannot read property 'wherearray' of undefined
at Object.framework.helpers.push (eval at <anonymous> (/home/arief/node_modules/total.js/index.js:1:14510), <anonymous>:2:21)
    at Array.eval [as 5] (eval at <anonymous> (/home/arief/node_modules/total.js/index.js:4:30662), <anonymous>:1:27)
    at Object.eval (eval at parse (/home/arief/node_modules/total.js/internal.js:1:29681), <anonymous>:1:251)
    at Object.Controller.view (/home/arief/node_modules/total.js/index.js:4:31012)
    at Object.query_homepage (/home/arief/web/examples-master/views/controllers/default.js:24:20)
    at Subscribe._execute (/home/arief/node_modules/total.js/index.js:3:23791)
    at Subscribe.execute (/home/arief/node_modules/total.js/index.js:3:22078)
    at Subscribe.prepare (/home/arief/node_modules/total.js/index.js:3:23249)
    at Subscribe._end (/home/arief/node_modules/total.js/index.js:3:25424)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
--------------------------------------------------------------------

Peter Širka

unread,
Jan 31, 2014, 6:31:20 PM1/31/14
to tot...@googlegroups.com
And with self.model it works?

arief nur andono

unread,
Feb 1, 2014, 12:25:46 AM2/1/14
to tot...@googlegroups.com
yes, it works with self.model

I've added self=this; in self.$model trial and it doesn't work..

Reply all
Reply to author
Forward
0 new messages