Angularjs,javascript传递数组
你好,任何人都可以帮我。如何将get方法的结果放入$scope.chat=[{}]变量中。提前谢谢Angularjs,javascript传递数组,javascript,angularjs,Javascript,Angularjs,你好,任何人都可以帮我。如何将get方法的结果放入$scope.chat=[{}]变量中。提前谢谢 app.controller('ChatCtrl', ["$scope","$http", function ($scope,$http) { $http({ method: 'GET', url: 'assets/controller/chat/messages.php' }).then(
app.controller('ChatCtrl', ["$scope","$http", function ($scope,$http) {
$http({
method: 'GET',
url: 'assets/controller/chat/messages.php'
}).then(
function(response1){
$scope.contents=response1.records;
});
$scope.selfIdUser = 50223456;
$scope.otherIdUser = 50223457;
$scope.setOtherId = function (value) {
$scope.otherIdUser = value;
};
var exampleDate = new Date().setTime(new Date().getTime() - 240000 * 60);
**$scope.chat = [{
"user": "bok",
"content": "test1",
"idUser": 1,
"idOther": 2
},{
"user": "bok",
"content": "test2",
"idUser": 1,
"idOther": 2
}];**
$scope.sendMessage = function () {
var newMessage = {
"user": "Peter Clark",
"avatar": "assets/images/avatar-1.jpg",
"date": new Date(),
"content": $scope.chatMessage,
"idUser": $scope.selfIdUser,
"idOther": $scope.otherIdUser
};
$scope.chat.push(newMessage);
console.log(newMessage);
$scope.chatMessage = '';
};
}]);
嗯,好的
我们有
$http({
method: 'GET',
url: 'assets/controller/chat/messages.php'
}).then(
function successCallback(response1){
alert(response1);// gives [Object, Object]?
console.log(response1);//Gives many values?
alert(response1[0][0]);//should print 'test'
alert(response1[0]['content']);//same/diff
$scope.contents=response1.records;
});
在控制台中,它提供了很多值,因此数据必须在那里
很抱歉回答了这些问题,但是没有测试我是盲人,你能做一把小提琴吗?我是在做正确的测试吗$outp=“”;而($rs=$result->fetch_array(MYSQLI_ASSOC)){if($outp!=”){$outp.=”,“;}$outp.=”{“idUser”:“..rs[“conversation_id”]。”,“;$outp.=”content:“..$rs[“msg”]”,“;$outp.=”user:“..$rs[“CompleteName”],“;$outp.=”,“$idOther:”.$rs[“to”][“to”],“$outp.=”id”],“''.$outp.''''''''''''''.[]$conn->close();回声(输出);新代码段是否提供了任何输出,我们需要知道数据是否在then(函数(response1)中,如果警报(response1[0][0]);//应该打印“test”是正确的假设,我可以了解更多。Lol不太清楚,但我得到了您SQL的结构,看起来还可以。警报和日志的响应如何?我想我在阅读文档时发现了一个错误。您调用了一个intent,这意味着(我们尝试了,但您不知道何时完成)这意味着我们正在尝试访问我们不知道是否存在(未定义)的数据。使用succesCallback()确保在返回数据之前不会启动函数。这意味着你在数据之前就在轨道上。我从这里得到了一个结果警报(response1.records[0]['content']);//test只需清除我的浏览器即可。然后得到它。