Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
selecting and filtering a model object
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
007design  
View profile   Translate to Translated (View Original)
 More options Feb 9, 2:51 pm
From: 007design <007design....@gmail.com>
Date: Thu, 9 Feb 2012 11:51:29 -0800 (PST)
Local: Thurs, Feb 9 2012 2:51 pm
Subject: selecting and filtering a model object
i need to set the model for a textfield to one of a number of items
but can't seem to figure out how to do it in 10.6
in 10.5 i could do something like:

ng:model="getMyModel('filterString')"

and in the controller do:

getMyValues = function(filterString) {
        for (var a in self.list) {
            if (self.list[a].name === filterString)
                return self.list[a].values;
        }
    };

since jsfiddle is down i must post the code here but here is an
example:

<div ng:app="MyApp">
    <div ng:controller="CtrlA">
        <select ng:options="l.name for l in list"
                ng:model="selection">
        </select>
        <textarea type="myWidget"
        ng:model="getMyValues()"></textarea>
            Selection: {{selection.name}}
    </div>
</div>

var appModule = angular.module('MyApp', []);
appModule.value('MySelection',{name:''});
appModule.value('MyList',[{name:'test1'},{name:'test2'}]);
appModule.value('MyOtherList',[
    {name:'test1', values:['a','b']},
    {name:'test2', values:['c','d']}
]);

function CtrlA(MySelection, MyList) {
    var self = this;
    self.list = MyList;
    self.selection = MySelection;

    self.getMyValues = function() {
        for (var a in self.list) {
            if (self.list[a].name === selection.name)
                return self.list[a].values;
        }
    };

}

CtrlA.$inject = ['MySelection','MyList'];

angular.inputType('myWidget', function() {
    this.$parseModel = function() {
        if (this.$modelValue) {
            var x = "";
            for (var a in this.$modelValue)
                x += this.$modelValue[a].optionValue+' and ';

            this.$viewValue = x;
        }
    };
    this.$parseView = function() {
        var vals = this.$viewValue.split(' and ');
        for (var a in vals)
            this.$modelValue[a].optionValue = vals[a];
    };

});

angular is awesome it's just taking some work to get my hear around
it.
thanks very much!
007

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vojta Jina  
View profile  
 More options Feb 10, 3:41 am
From: Vojta Jina <vojta.j...@gmail.com>
Date: Fri, 10 Feb 2012 00:41:33 -0800 (PST)
Local: Fri, Feb 10 2012 3:41 am
Subject: Re: selecting and filtering a model object

You should have stable model - two same objects are same reference (not
having selection different object with the same name property).

I guess you want something like this: http://jsfiddle.net/vojtajina/dehDh/

V.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
007design  
View profile  
 More options Feb 10, 10:02 am
From: 007design <007design....@gmail.com>
Date: Fri, 10 Feb 2012 07:02:48 -0800 (PST)
Local: Fri, Feb 10 2012 10:02 am
Subject: Re: selecting and filtering a model object
thanks so much for your reply but i'm getting a 404 on that fiddle
link :(
007

On Feb 10, 2:41 am, Vojta Jina <vojta.j...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vojta Jina  
View profile  
 More options Feb 10, 6:04 pm
From: Vojta Jina <vojta.j...@gmail.com>
Date: Fri, 10 Feb 2012 15:04:13 -0800 (PST)
Local: Fri, Feb 10 2012 6:04 pm
Subject: Re: selecting and filtering a model object

jsfiddle was down yesterday, should be fine now...

V.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
007design  
View profile  
 More options Feb 12, 8:02 pm
From: 007design <007design....@gmail.com>
Date: Sun, 12 Feb 2012 17:02:15 -0800 (PST)
Local: Sun, Feb 12 2012 8:02 pm
Subject: Re: selecting and filtering a model object
http://jsfiddle.net/007design/uA8Tm/

ok, here's a followup with example fiddle.

say you have a list of products which each have several options
(price, size, color, etc).  some of these options are global to all
items (price) but others are specific to each product.  for example,
if you have a "shirt" product, it would have a "size" option but a
"blanket" product might only come in one size so it needs no "size"
option.
the list of global options and their possible values is maintained
separately from the individual product options and their values.

if you examine the fiddle above you can see where i am at the moment.
it works but it's quite ugly.  can anyone give me some idea of how to
clean this up, a better way to do it?

thanks a lot for all your help!
007


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Witold Szczerba  
View profile  
 More options Feb 16, 5:46 pm
From: Witold Szczerba <pljosh.m...@gmail.com>
Date: Thu, 16 Feb 2012 23:46:36 +0100
Local: Thurs, Feb 16 2012 5:46 pm
Subject: Re: [angular.js] Re: selecting and filtering a model object
Wow, this is amazing.
I was starring at that code for few minutes and still I have
completely no idea what does it do and what does it do it for. The
part with loops in loops in loops in etc... is plain crazy, hehe :)
I would definitely reject that code and sit down with developer to try
to figure out the true idea behind that.

Regards,
Witold Szczerba

On 13 February 2012 02:02, 007design <007design....@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
007design  
View profile  
 More options Feb 22, 6:20 pm
From: 007design <007design....@gmail.com>
Date: Wed, 22 Feb 2012 15:20:35 -0800 (PST)
Local: Wed, Feb 22 2012 6:20 pm
Subject: Re: selecting and filtering a model object
see if this makes it clearer.
each product contains a list of options (size, color, price, etc.)
each of these product options has a value (small, red, $42, etc)
"static options" are options which EVERY product has.  for example,
every product has a price but not all products have a size or a color.

when the app loads, it grabs the list of "static options" from the
server and the list of products.  they're two separate models.
it then displays the list of products.  selecting a product will
display the options for that product in select fields with the
appropriate values selected (or just as text fields if there is not
more than one possible choice).
here's the tricky bit.  the ng:model of the select field is the
'value' property of each product (i.e. product.name="shirt,
product.value = "small").
if the product option is a 'static option', ng:options for the select
field should be the values of the static option object which matches
the product option.
so, what all those ugly loops do is look thru each product option
matching it's name property against the name of each static option
object.  when it finds the matching option it adds a property called
staticValues to the product object consisting of the values for the
matching static option.  also, it sets the 'value' property of the
product to the matching static value object instead of just a string.

it's quite awful, i know, but the only way I can think of to get
around it.  how do you define relationships between two objects
retrieved at different times?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vojta Jina  
View profile  
 More options Feb 22, 6:46 pm
From: Vojta Jina <vojta.j...@gmail.com>
Date: Wed, 22 Feb 2012 15:46:49 -0800 (PST)
Local: Wed, Feb 22 2012 6:46 pm
Subject: Re: selecting and filtering a model object
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »