I am creating a survey app. In this a question can have multiple answers. So I am storing answers in a collection. I am using Backbone.CollectionBinder to render views by passing view class. Each view have "Remove Answer" link.
Lets say there are 3 answers added to collection. Now if I remove 1st answer it always gives me last model in that view class. So the problem is it always gives me last model inside answer view.
We need some more information. The docs (http://backbonejs.org/#Collection-remove) state that the removed model is returned from the collection. I've used it heavily without issue. It sounds like your reusing the same view or iterating incorrectly. Please post some code.
I got the answer of my question from following post
http://lostechies.com/derickbailey/2011/10/11/backbone-js-getting-the-model-for-a-clicked-element/
Related
I have to load multiple answers when user click a question.There are multiple questions and each has multiple answers.but when i click second question,the answers of first question are also changing.
I have assigned div id dynamically from my controller in ng-repeat,but when i load data into the div,it always loading data into the first question answers div.div ids are unique in ng-repeat but answers of every question are displaying in all divs.
Sounds to me that you are using the same ng-model for both questions. If you link some of your code I could better examine it.
Use
$('#QuestionID').find('#answerId');
select answer id inside particular question instead of directly taking
$('#answerId')
https://gist.github.com/djdaniels90/948704c58242c4bb08b5
I am having trouble with a dynamically generated quiz structure. I am aware of $parent. scope. I have attempted to implement it but the form is still not working as desired. I have linked the gist site; any help on this would be greatly appreciated.
Each question is a form in itself and the entire quiz is a form of question forms. Each question form contains x number of possible answers. Furthermore, a quiz can have y number of questions. Therefore we have a loop within a loop; ie: we are creating some nested child scopes.
Ultimately, each question can only have one answer, ie: only one checkbox can be clicked for each subforms. I can rather easily hack together a method using pure JS or jquery to grab the form elements but I know there is a way to do this in Angular, I am pretty close I believe but can't get the last little bit. Ideally, I would like either the questions to update corresponding models, which could be created in a array within the controller. Or the form submit action to upload the entire quiz data.
Any help on where I am going wrong would be great.
You are missing one attribute and need a variable for assigning answers to.
The NAME attribute takes care of the grouping and the model cannot be the question object itself, but rather an attribute of the question itself.
<input type="radio" name='{{question.question}}' ng-value="{{answer}}" ng-model="question.answer">
Here's a working version:
http://plnkr.co/edit/fACdq8DGvJel9An87GyA?p=preview
I have a controller for posts and an element for comments. I want to include the posts view somehow in comment element. Is this possible to include the PostsController view into an element?
I know how to include elements but never heard or thought of including Controller views.
You can get the data for the PostsController view using requestAction. If you want to include view-layer code in two different places, pull it into an element - that's what they're for.
I am new to Cakephp and indeed OOP, so forgive me if i haven't fully grasped the MVC concept yet. I have search a lot but cannot find an answer - perhaps my way of working below is not correct. I hope you can help.
I am building a site which will have many elements relating to their tables and data. I intend to use a view to pick and choose the relevant elements and any parameters needed.
For example, the homepage of my site will have two elements - a latestusers element and a latestscores element. I am trying to use a view not related to either the users or scores models/controllers, stored in 'other/index.ctp'.
I have tried using set() to pass a variable from the users controller (latestusers action) into the other/index.ctp view, but the viewVars remain empty. Could this be due to scope of the variable (i think it is fine for a view in the users folder, i.e. a view specific to the users controller).
I could achieve what i want to do by using global variables, but i think this is missing the point of MVC/OOP. Would be grateful for any suggestions.
I can include code if need be - it is fairly basic at this stage - but i feel my problem lies with how i am going about things, not the code itself.
Cheers,
James
Yes, the issue is with the scope. If you're going to use variables in the element you'll need to pass them in from your view. So the flow would look something like this
Controller $this->set()s the variable into your current view/layout
Your view/layout calls $this->element with the current element path.
Your element uses those variables.
In number 2 you need to pass your variables as an array of data. This section on the cookbook gives more information : http://book.cakephp.org/view/1081/Elements
<?php echo$this->element('helpbox',
array("helptext" => "Oh, this text is very helpful."));?>
Note - I didn't understand part of the question. Just want to make sure you are passing data to the correct view. You should not be calling the view of another controller in your active controller.
Your other/index.ctp should be an element and that element should be called from your layout.
I read a lot about tagging in CakePHP but I can't find a "clean" way to save a Post and the Tags to this post. I have all which is necessary the Post Table, Model and Controller, the Tag table, Model and Controller and the posts_tags table. I created the HABTM Associations in the Post and the Tag Model.
If I want to save a new post, I want that CakePHP automagically saves the tags associated to that post, but I can't find the right way for that. In most of the tutorials you have to use a "helper" Function (http://www.jamesfairhurst.co.uk/posts/view/full_cakephp_application_part_5 => "_parse_genres") or something like that, but I thought the deal with CakePHP is it, that this is all done by Cake once you set it up right.
So my question, is there a "clean"-Cake-way to do it, or do I have to use a helper function?
I find it very hard to believe that you didn't find a "proper" way to handle HABTM. There are many, many articles about it. I believe that Cake will save your tags if you set your data array properly. A quick search on The Bakery:
http://bakery.cakephp.org/articles/search/3/HABTM
Will reveal enough. My guess is that you're looking for this:
http://bakery.cakephp.org/articles/view/simple-tagging-behavior
(Note that there is a component which does the same thing, but model behaviour is the right way to go)