-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppController.j
74 lines (61 loc) · 2.3 KB
/
AppController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* AppController.j
* Cappuccino-KVC-tests
*
* Created by You on February 10, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
@outlet CPWindow theWindow; //this "outlet" is connected automatically by the Cib
myObject testClassObject;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}
- (void)awakeFromCib
{
testClassObject = [[myObject alloc] init];
//bug with operators in key path....
console.log(@"FIRST TEST- WORKS");
var data = [testClassObject valueForKey:@"scoreArray"];
console.log(data);
console.log([data valueForKeyPath:@"@sum.intValue"]);
console.log(@"SECOND TEST- DOESN'T WORK");
console.log([testClassObject valueForKeyPath:@"[email protected]"]);
// Also doesn't work:
// console.log([testClassObject valueForKeyPath:@"@sum.scoreArray"]);
// alert([testClassObject valueForKeyPath:@"[email protected]"]);
}
@end
@implementation myObject : CPObject
{
CPArray scoreArray @accessors(readonly);
CPString JSONString;
CPArray workingArray;
}
- (void)init
{
if (self = [super init])
{
scoreArray = [1, 1, 1, 1, 1, 1, 1, 1, 1];
JSONString = '[{"classID":5,"className":"test","requireInstructorApproval":1},{"classID":6,"className":"test1","requireInstructorApproval":1},{"classID":7,"className":"test2","requireInstructorApproval":1},{"classID":8,"className":"test3","requireInstructorApproval":0}]';
var objectRepresentation = [JSONString objectFromJSON];
/* Doesn't work:
var testDictionary = [CPDictionary dictionaryWithJSObject:objectRepresentation recursively:YES];
alert([testDictionary valueForKeyPath:@"classID"]);
*/
workingArray = [[CPArray alloc] init];
for (i=0; i<objectRepresentation.length; i++)
{
var testDictionary = [CPDictionary dictionaryWithJSObject:objectRepresentation[i] recursively:YES];
alert([testDictionary valueForKeyPath:@"classID"]);
[workingArray addObject:testDictionary];
}
alert([workingArray valueForKeyPath:@"@avg.classID"]); //works!
}
return self;
}
@end