下面你好朋友是我的数组。
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);
这工作正常,现在我想设置“关键”想要。
$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”元素。 在数组中我有很多的元素,我怎么能看到所有元素“关键”。
请帮助
谢谢
显然,它不会与'simpleData.key'一起工作 - 没有这样的事情。 – 2014-11-08 19:15:30
@NewDev我现在编辑我的问题检查。 – 2014-11-08 19:19:13
你的例子中'simpleData'究竟是什么? – 2014-11-08 19:22:12