Created
February 27, 2012 18:06
-
-
Save snay2/1925904 to your computer and use it in GitHub Desktop.
Simple example for using arrays in an entity variable in KRL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruleset a163x156 { | |
meta { | |
name "Arrays" | |
description << | |
Some experiments using arrays in KRL | |
>> | |
author "Steve Nay" | |
logging on | |
} | |
dispatch { } | |
global { } | |
rule framework { | |
select when pageview ".*" | |
pre { | |
msg = << | |
This is the current list of items: | |
<div id="items"></div> | |
Add a new one: | |
<form id="array-item-add"> | |
<input type="text" name="item" /> | |
<input type="submit" /> | |
</form> | |
Or, reset the list: <input type="button" id="reset" value="Reset" /> | |
>>; | |
} | |
{ | |
notify("Experimenting with arrays", msg) with sticky=true; | |
watch("#array-item-add", "submit"); | |
watch("#reset", "click"); | |
} | |
} | |
rule populate { | |
select when pageview ".*" | |
foreach ent:myarray setting (item) | |
append("#items", "#{item}<br />"); | |
} | |
rule item_add { | |
select when web submit "array-item-add" | |
pre { | |
item = event:param("item"); | |
item_array = ["#{item}"]; | |
new_array = item_array.union(ent:myarray); | |
msg = << | |
Added item "#{item}". | |
>>; | |
} | |
notify("Experimenting with arrays", msg); | |
fired { | |
set ent:myarray new_array; | |
} | |
} | |
rule reset { | |
select when web click "reset" | |
fired { | |
set ent:myarray []; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment