Thursday, 15 May 2014

javascript - Angularjs orderby objects keys -


So, I am trying to create a sorting list in the Attributes. Once a person clicks the name of the value, it updates the dom and displays the data accordingly. Bracelets, charms, and so on ... I know that I can do something like this:

Charms', 'ear kali', ...]; // sorting option $ scope.sort = 'bracelet'; // Set a default sortba item $ scope.active = function (x) {return x === $ scope.sort? 'Active': ''; }; $ Scope.setSort = Function (type) {$ scope.sort = type.toLowerCase (); };

But this is just an object I have several objects coming from the server. Here is my category object:

  {"Pandora": {"id": "1", "s1": {"d1" "cube", " "D6": "Jewelry", "D5": "Pendant", "D7": "Bracelet", "D2": "Cheams", "D3": "Earrings", "D4": " Necklace "," D6 "rings"}}}  

I'm reading that you can not use an order of angles without the array of objects. I have this code in my controller:

  $ scope.catData = [];  

Then I have a factory which The server goes on to catch json

  dataFactory.getCat (). Then (function (res) {$ scope .catData = res.data;});  

here My code looks like

  & lt; li ng-repeat = "catData" (key, value) & gt; & lt; a href = "#" data-id = '{ {Value.id}} 'class = "anchor" & gt; {{key}}  gt; & lt; ul class = "sub" ng-class = "{true:' active slides'} [Value.id == 1] "& gt; & lt; span ng- repeat =" hi value.s1 " 
  • I & gt; {{Hi}} & lt; / a & gt; & lt; / li & gt; & lt; / span & gt; & lt; / ul & gt; & lt; / li & gt; / Code>

    I'm thinking that when I set $ scope.catData in an array, then set $ scope.catData = res.data Override I can set the $ scope.catData = [res.data] but I do not think it's the right way to do it (or maybe?).

    < P> Thanks ng click and

  • > N

    Below is an example and a JSFiddle:

    HTML

    Some display text which is $ scope.he var -> gt; & lt; H2 ng-model = "hi" & gt; {{Hi}} & lt; / H2 & gt; & Lt; Ul ng-repeat = "obj in data" & gt; & Lt ;! - Repeats data and includes function calls for value - & gt; & Lt; Li ng-repeat = "entry in obj.s1" ng-click = "update" & gt; & Gt; Button ng-value = "{{entry}}" & gt; {{Entry}} & lt; / Button & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt; / Div & gt;

    JS

      var app = angular Module ('myApp', []); // your data plus var myData = "... some JSON data ..."; App.controller ('Pandora Controller', ['$ scope', function ($ area) {$ scope.hi = "Select a pandora product:" $ scope.data = myData; $ scope.update = function (val) { $ Scope.hi = val;}}]));  


    No comments:

    Post a Comment