【发布时间】:2014-11-08 19:07:35
【问题描述】:
你好下面的朋友是我的数组。
data.php 文件
$array = array(
'0' => array(
'id' = 1,
'name' = 'test',
'key' = array(
'0' = 'key1',
'1' = 'key2',
'2' = 'key3'
)
),
'1' => array(
'id' = 3,
'name' = 'test3',
'key' = array(
'0' = 'key7',
'1' = 'key8',
'2' = 'key9'
)
),
'2' => array(
'id' = 15,
'name' = 'test30',
'key' = array(
'0' = 'key4',
'1' = 'key5',
'2' = 'key6'
)
)
);
echo json_encode($array);
下面是我的js代码。
$http({method: 'GET', url: $rootScope.serverURL+'data.php'}).
success(function (data, status, headers, config) {
$rootScope.simpleData = data;
}).
error(function (data, status, headers, config) {
});
$scope.$watch('page + numPage + simpleData', function() {
console.log('working');
},true);
现在我想在“key”上设置希望。
$scope.$watch('page + numPage + simpleData.key', function() {
console.log('not working');
},true);
当我像这样工作正常编写此代码时,此代码不起作用。
$scope.$watch('page + numPage + simpleData[0].key', function() {
console.log('working');
},true);
当我编写 js 时,它工作正常。角度 js 监视键,但仅适用于“0”元素。 在数组中我有很多元素我如何查看所有元素“Key”。
请帮忙
谢谢
【问题讨论】:
-
显然,它不适用于
simpleData.key- 没有这样的东西。 -
@NewDev 我现在编辑我的问题检查。
-
在您的示例中,
simpleData到底是什么? -
@NewDev in simpleData 我将存储我的 json 数组,请在上面的代码中正确查看,谢谢
-
@NewDev 我现在编辑我的代码检查。
标签: javascript angularjs multidimensional-array