0
Answered

How to write to list items?

TuomoHautala 9 years ago in iRidium Script / Interface scripts updated by Dmitry - support (expert) 9 years ago 3

I have created this simple project where I want to read and write on my list level items.

I know now how to read from them but having hard time trying to write to them.

So. How it's done? For example how do i write incoming feedbacks to different levels in list?


var List_1 = IR.GetItem("Frontpage").GetItem("Frontpage_list");


IR.AddListener(IR.EVENT_START,0,function()
{
List_1.Template = "Frontpage_list_template";
List_1.CreateItem(0, 1, {Text: "$V"});
List_1.CreateItem(1, 1, {Text: "$V"});
List_1.CreateItem(2, 1, {Text: "$V"});
List_1.CreateItem(3, 1, {Text: "$V"});
List_1.CreateItem(4, 1, {Text: "$V"});
List_1.CreateItem(5, 1, {Text: "$V"});
List_1.CreateItem(6, 1, {Text: "$V"});
List_1.CreateItem(7, 1, {Text: "$V"});
List_1.CreateItem(8, 1, {Text: "$V"});
});
IR.AddListener(IR.EVENT_LIST_ITEM_CHANGE, List_1, function(Item, Subitem, TypeEvent, object){
switch(Item){
case 0:
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
case 1:
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
case 2:
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
}
});


Answered

Hello!


To write a value to a list item, you need do the following


// Subscribe to the event of changing the value of the List subitem and write for the subitem

// value 32 in the property X
IR.AddListener(IR.EVENT_LIST_ITEM_CHANGE, List_1, function(Item, Subitem, TypeEvent, object){
// The property X will be rewritten and the item will be moved to the corresponding position
object.X = 32;
});

Ok.

But how can I write specific level value to specific level?


For example if I have created 8 level items to my list and I want to change Item 1 level value to whatever value my equipment is sending to iridium.


IR.AddListener(IR.EVENT_START,0,function()

{
List_1.Template = "Frontpage_list_template";
List_1.CreateItem(0, 1, {Text: "$V"});
List_1.CreateItem(1, 1, {Text: "$V"});
List_1.CreateItem(2, 1, {Text: "$V"});
List_1.CreateItem(3, 1, {Text: "$V"});
List_1.CreateItem(4, 1, {Text: "$V"});
List_1.CreateItem(5, 1, {Text: "$V"});
List_1.CreateItem(6, 1, {Text: "$V"});
List_1.CreateItem(7, 1, {Text: "$V"});
List_1.CreateItem(8, 1, {Text: "$V"});
});

Unfortunately, to write data to a specific list item is possible only through create this list item.

I.e. if you want to change the value of a list item, you need to recreate it with the new value.

For example:



var List_1 = IR.GetItem("Frontpage").GetItem("Frontpage_list");


IR.AddListener(IR.EVENT_START,0,function()
{
List_1.Template = "Frontpage_list_template";
List_1.CreateItem(0, 1, {Text: "$V"});
List_1.CreateItem(1, 1, {Text: "$V"});
List_1.CreateItem(2, 1, {Text: "$V"});
List_1.CreateItem(3, 1, {Text: "$V"});
List_1.CreateItem(4, 1, {Text: "$V"});
List_1.CreateItem(5, 1, {Text: "$V"});
List_1.CreateItem(6, 1, {Text: "$V"});
List_1.CreateItem(7, 1, {Text: "$V"});
List_1.CreateItem(8, 1, {Text: "$V"});
});
IR.AddListener(IR.EVENT_LIST_ITEM_CHANGE, List_1, function(Item, Subitem, TypeEvent, object){

switch(Item){
case 0:
List_1.CreateItem(0, 1, {Text: "!!!!!!"});
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
case 1:
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
case 2:
IR.Log("Level = "+Item+" Value = "+object.Value);
break;
}
});