Announcement

Collapse
No announcement yet.

JS model set hasMany 'xxxIds' field not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JS model set hasMany 'xxxIds' field not working

    Hi there,

    I'm trying to do a this.model.set('xxxxxIds', [...]); on a "hasMany" field but the 'views/fields/link-multiple' view doesn't seem to take my .set() into concideration.
    It was working very well when this field was a "belongsTo" but now it doesn't. Am I doing the wrong thing ?

    The code is below

    Click image for larger version

Name:	image.png
Views:	191
Size:	42.3 KB
ID:	97309


    Regards,
    Firyo.

  • #2
    you try this (if the field view is discountsIds) and extends (views/fields/link-multiple)

    PHP Code:
    this.model.set(this.idsNamediscountsIds);
    this.model.set(this.nameHashNamenameMap); // get some name mapper for the discount collection 

    Comment


    • #3
      The code I screenshoted is inside a view setup handler not a views/fields/link-multiple.
      I already tried to do both .set('discountsIds, [...]) and .set('discountsNames, {...}) but it didn't work either.

      Comment


      • #4
        You set the same value. Arrays in JS are objects. Try to clone it right after 'get'.

        Code:
        const discountsIds = Espo.Utils.clone(this.model.get('discountsIds'));
        or

        Code:
        const discountsIds = [...this.model.get('discountsIds')];

        Comment


        • #5
          Originally posted by yuri View Post
          You set the same value. Arrays in JS are objects. Try to clone it right after 'get'.

          Code:
          const discountsIds = Espo.Utils.clone(this.model.get('discountsIds'));
          or

          Code:
          const discountsIds = [...this.model.get('discountsIds')];
          Well, I always forgot about this JS specificity, thank you Yuri.

          Comment

          Working...
          X