javascript - comparing values from two different context using mustache and canjs -
Let's say that I have this mustache template below. Contacts and categories are basically an array of objects:
& lt; Script type = "text / mustache" id = "contactsList" & gt; & Lt; Ul class = "clearfix" & gt; {{# Contact}} & lt; Li class = "contact span8" & gt; & Lt; A href = "javascript: //" class = "remove" & gt; & Lt; I class = "icon-remove" & gt; & Lt; / I & gt; & Lt; / A & gt; & Lt; Form & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "span2" & gt; & Lt; Img src = "img / canjs.jpg" width = "100" height = "100" & gt; & Lt; / Div & gt; & Lt; Div class = "span3" & gt; & Lt; Input type = "text" name = "name" placeholder = "add name" value = "{{name}}" & gt; & Lt; Select Name = "Category" & gt; {{#categories}} & lt; Option value = "{{data}}" {{same category category}} & gt; {{Name}} & lt; / Options & gt; {{/ Categories}} & lt; / Select & gt; & Lt; / Div & gt; & Lt; Div class = "span3" & gt; & Lt; Label & gt; Address & lt; / Labels & gt; & Lt; Input type = "article" name = "address" value = "{{address}}" & gt; & Lt; Label & gt; Phone & lt; / Labels & gt; & Lt; Input type = "text" name = "phone" value = "{{phone}}" & gt; & Lt; Label & gt; Email & lt; / Labels & gt; & Lt; Input type = "text" name = "email" value = "{{email}}" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Li & gt; {{/ Contacts}} & lt; / Ul & gt; & Lt; / Script & gt;
What I want to do, the "selected" is generated by the category of contact tags. Category and categories. By comparing data.
That is why I had to apply the same class as:
can.mustache.registerHelper ('sameCategory', function (contactCategoryId, Category ID) { Console.log (contactCategoryId); console.log (categoryId); var results = contactCategoryId == category ID? "Selected": ""; console.log (results); results returned;});
Unfortunately, I want to get the objects for both of them on the basis of stars, so that the situation of my equality fails. What am I doing wrong?
var contact = [{ID: 1, name: 'William', address: '1' INGS Way ', e-mail:' William @ Hussar.com ', phone : '0123456789', Category: 'colleague'}, {ID: 2, name: 'Laura', address: '1 canges that', email: 'Laura@starbuck.com', phone: '0123456789', Category: Friend '}, {id: 3, name:' li ', address:' 1 canges them ', email:' lee@apollo.com ', phone:' 0123456789 ', category:' family '}]; (Id: 'family'), {id: 2, name: 'friend', data: 'friend'}, {id: 3, name: 'co-workers, data:' colleagues'}];
I have taken these examples from an example article.
I was looking at my code on a bela, and I could not repeat it, though maybe you Can.computes were getting that you will need to run as a function before getting the price.
However, the assistant is completely unnecessary with the can / view / bindings plugin, simply set the set-value = "category" on your selection and it will automatically select the correct option ( And update the modified value).
Displayed in a Bella:
& lt; Select name = "category" can-value = "category" & gt; {{#categories}} & lt; Option value = "{{data}}" & gt; {{Name}} & lt; / Options & gt; {{/ Categories}} & lt; / Select & gt;
Comments
Post a Comment