Setting sub array values in a list

edited December 2013 in Technical questions

What is the recommended way to set the data field in the memberActionListView so that the actions array (which is a subarray) iis displayed? So that when the member record is updated the actions list is updated as well?

{ view:"list", select:true, borderless:true, id:"memberActionListView",
template:"#dueDate# - #action#,
data: ????member_set.getSelectedId().actions???
}

var member_set = [
{
"memberRecordID": "280",
"first": "David",
"last": "Brown",
"phone": "801-123-1234",
"email": "Brown534@gmail.com",
"birthday": "05/05/2009",
"misc": "Head Mechanic",
"actions": [
{
"action": "Test flywheel",
"dueDate": "08/02/2036",
"completed": "false"
},
{
"action": "Update shocks",
"dueDate": "08/02/2036",
"completed": "false"
},
{
"action": "Repair seals",
"dueDate": "08/02/2036",
"completed": "false"
}
]
}
];

Comments

  • If you want to show data from sub sub-array along with the main record data - you can use a template defined as function. It allows to implement any kind of data logic.

    Check the next sample http://snippet.webix.io/e44bb439

  • So if I was trying to display the subarray for let's say the next person in the list I would need to set that in the template portion and not change the data I assume.

  • The idea is to only populate the list with one of the members sub array - to do that would you still use the template like you did?

  • If the data set for the array is still member_set then the template will return a line for each record in the member_set as it should. What I want is to know the best way to set the data in the list to the subarray for that one member. Does that make sense?

  • The idea is to only populate the list with one of the members sub array

    In such case you can use

    { view:"list", template:"#dueDate# - #action#, data: member_set[0].actions }
    

    member set is a static js array, so you can't use any methods on it, except of normal array operators

    To have a bit more flexibility, you can parse it to the data collection

    var members = new webix.DataCollection({ data:member_set });
    //now you can use
    { view:"list", template:"#dueDate# - #action#, data: members.get(1).actions }
    

    Here you can get member by its id ( not by index as in case of simple js array )

    http://snippet.webix.io/ba86ae4f

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!