0

I have a drop down arrow, but all of the elements within the drop down arrow are not sorted in a healthy way. I'm trying to use the orderBy angular filter, but have been having some struggles. After doing a little bugging, I believe that the problem is because what i'm needing to have displayed is nested within some objects.

My front end looks like

    %input-md{ type: 'select', "ng-model" => "vm.form.group", required: true, options: 'vm.groups', placeholder: 'Select your group' }

My controller has this function in it that addresses the groups.

  init = ->
    success = (groups) ->
      vm.groups = groups
      return

So I first threw in a debugger in the function right after groups gets defined, upon which I searched for groups in the JS console, and received a number or objects that looked like this.

text : "American group"
value : Object
__proto__ : Object

Looks kinda like: enter image description here

I need these to be sorted by their text field so in this case American group

I tried going at

    %input-md{ type: 'select', "ng-model" => "vm.form.group", required: true, options: "object in vm.groups | orderBy: 'text'", placeholder: 'Select your group' }

But I keep getting an error not recognizing text. Its Failed to execute 'setAttribute' on 'Element': 'text'' is not a valid attribute name.

So I'm not sure what I am missing, and i'm hoping someone can take a quick look and hopefully straighten me out a bit.

***** Edit ****

After doing some further research, I've learned that orderBy() does not work with objects, it only works with arrays. Which explains why my approach was not working. (still trying to figure out how to actually go about with a fix like this)

1 Answer 1

1

Change your options attribute to: object.text for object in data | orderBy: 'text'

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry bud, but I gave that a try and did not have any success. I believe it is because orderBy does not work with objects
I have corrected my answer, check this fillde jsfiddle.net/112g/Levo00so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.