这是我的角度代码
function load_interest(){
console.log("in angular");
$http.get('http://localhost:3000/interest').success(function(data){
console.log("and");
console.log(data.interest);
$scope.interests=data;
});
};
这是我的HTML代码:
<div ng-app="myApp" ng-controller="orderCtrl">
<table class="table table-striped">
<tbody ng-repeat="inter in interests">
<tr>
<td><li>{{ inter.interest}}</li></td>
</tr>
</tbody>
</table>
这是我的数据:
{ _id: '56371e0b2c456955b041b278',
username: 'mamba@gmail.com',
interest: 'cricket'
}, {
_id: '56371e3f2c456955b041b279',
username: 'mamba@gmail.com',
interest: 'cricket'
}, {
_id: '56371e7c2c456955b041b27a',
username: 'mamba@gmail.com',
interest: 'cricket'
},
此方法早先使用mySQL数据库。有人可以帮帮我吗?我是Mongodb的新手。
当我使用{{interest}}时,我可以看到整个数据 [{ “_id”: “56371e0b2c456955b041b278”, “用户名”: “mamba@gmail.com”, “利息”: “蟋蟀”},{ “_ ID”: “56371e3f2c456955b041b279”, “用户名”:“mamba@gmail.com ”, “利息”: “蟋蟀”},{ “_ ID”: “56371e7c2c456955b041b27a”, “用户名”: “mamba@gmail.com”, “利息”: “蟋蟀”},{ “_ ID”: “56371ec92c456955b041b27b” “用户名”: “mamba@gmail.com”, “利息”: “蟋蟀”},{ “_ ID”: “56371ed82c456955b041b27c”, “用户名”: “mamba@gmail.com”, “利息”: “蟋蟀”} { “_ ID”: “56371ee32c456955b041b27d”, “用户名”: “mamba@gmail.com”, “利息”: “蟋蟀”},{ “_ ID”: “563979d38e40c191ff91e338”, “用户名”:“mamba@gmail.com ”, “利息”: “篮球”}]
答案 0 :(得分:0)
将你的html更改为:
public class Incidente implements Parcelable, Parcelable {
String name;
String type;
String street;
int streetNumber;
String city;
ArrayList<String> contacts;
protected Incidente(Parcel in) {
name = in.readString();
type = in.readString();
street = in.readString();
streetNumber = in.readInt();
city = in.readString();
if (in.readByte() == 0x01) {
contacts = new ArrayList<String>();
in.readList(contacts, String.class.getClassLoader());
} else {
contacts = null;
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(type);
dest.writeString(street);
dest.writeInt(streetNumber);
dest.writeString(city);
if (contacts == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(contacts);
}
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<Incidente> CREATOR = new Parcelable.Creator<Incidente>() {
@Override
public Incidente createFromParcel(Parcel in) {
return new Incidente(in);
}
@Override
public Incidente[] newArray(int size) {
return new Incidente[size];
}
};
}
或保持html不变,但将控制器更改为
<tbody ng-repeat="inter in interests.data"> ...
否则你的ng-repear不会在兴趣上循环,而是在数据对象上循环。
是的, $scope.interests = data.interests;
应该是一个数组:)
答案 1 :(得分:0)
以下是演示http://dojo.telerik.com/ujirI
$scope.interests = [];
$scope.interests.push({
_id: '56371e0b2c456955b041b278',
username: 'mamba@gmail.com',
interest: 'cricket'
}, {
_id: '56371e3f2c456955b041b279',
username: 'mamba@gmail.com',
interest: 'cricket'
}, {
_id: '56371e7c2c456955b041b27a',
username: 'mamba@gmail.com',
interest: 'cricket'
});
希望这可以帮到你