Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im trying to load some data from a local json file and put it inside a jquery mobile listview using angularJS. Im having a hard time to understand how do I combine the ng-repeat with the data-role="listview". For the fiddle example i used an online hosted json file from filltext.com.

i updated the code according to Danyu's suggestion, but it still doesnt work. Now all the usernames appear in ONE li element, instead of one username in one li element.

fiddle link: http://jsfiddle.net/hh8hS/

html code:

<div data-role="page" id="scientists" ng-app="test">
    <div data-role="header"><h3>jquery mobile + json call test</h3></div>
    <div data-role="content">
        <div ng-controller="controller">
            <ul data-role="listview" data-inset="true" data-filter="true">
                <li ng-repeat="item in itemSet">{{item.username}}</li>
            </ul>
        </div>
    </div>
</div>

JS code:

var data1= [
    {
        "id": 1,
        "email": "[email protected]",
        "username": "NCollier",
        "password": "XIsyw"
    },
    {
        "id": 2,
        "email": "[email protected]",
        "username": "NDerucher",
        "password": "f687l"
    },
    {
        "id": 3,
        "email": "[email protected]",
        "username": "DBario",
        "password": "Vl7ND"
    },
    {
        "id": 4,
        "email": "[email protected]",
        "username": "LOng",
        "password": "JeTnK"
    }
    ];

var myApp=angular.module("test",[]);

myApp.controller("controller", function($scope,$http){
   $http.get("data1").success(function(data){
      $scope.itemSet=data;
   });
});

EDIT: apparently the code works with the little change Danyu suggested, it was a local problem on my PC.

share|improve this question
    
If no data is loaded and displayed, try URL in the browser see if there is any data being returned. –  Danyu Jun 7 at 17:24

1 Answer 1

up vote 1 down vote accepted

You should use ng-repeat on the <li> element instead of the parent <ul>:

<li ng-repeat="item in scientists">
   {{item.username}}
</li>
share|improve this answer
    
i inserted the ng-repeat inside the li element, and now all the usernames are printed inside one li element. what else am i missing? –  Alex Tal Jun 7 at 19:52
    
Could you check the structure of the returned data? If the data is an array, like data=[{username:...},{username:...}], it should work. But if it is an object that has an array, like data={[...]}, all names will be built into a single li. –  Danyu Jun 7 at 20:17
    
the structure of the data is [{"id": 1,"username": "a"},{...}] –  Alex Tal Jun 7 at 20:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.