计算的属性不会在前端更新

索帕瓜(P. Sopacua)

我有一个组件,scanstart-participants-count该组件将显示添加到指定扫描和目标受众的参与者总数。在我的车把中,我用调用了该组件,{{scanstart-participants-count scan=scan targetAudience=targetAudience}}并且一切正常,除非当isValid我的participant模型中更改true为前端计数时停留在上0我只是不知道我在做什么错

组件:scanstart-participants-count.js

从'ember'导入Ember

export default Ember.Component.extend({
    tagName:           'div',
    classNames:        'participant',
    scan:              null,
    targetAudience:    null,

    scanParticipants:  Ember.computed('scan.id', 'targetAudience.scanParticipants.[]', function () {
        // Default properties
        const scanId           = this.get('scan.id')
        const scanParticipants = this.get('targetAudience.scanParticipants')

        console.log('scanParticipants count scan: '+scanParticipants.filterBy('scan.id', scanId).get('length')) // Correct output

        // Filter by scan ID.
        return scanParticipants.filterBy('scan.id', scanId)
    }),
    participants:      Ember.computed('scanParticipants.[]', function () {
        // Default properties
        const scanParticipants = this.get('scanParticipants')

        // Map by participant
        return scanParticipants.mapBy('participant')
    }),
    // TODO: Change "[email protected]" to "[email protected]" after update to 2.3.0
    participantsValid: Ember.computed('[email protected]', function () {
        // Default properties
        const participants = this.get('participants')

        console.log('participants count: '+this.get('participants').get('length')) // Correct output
        console.log('participants valid count: '+this.get('participants').filterBy('participantValid', false).get('length')) // Correct out put when loads first time, nothing happens when the isValid column change's to true. (First time: participantsValid = true = 0, participantsValid = false = 3)

        // Filter by isValid = true.
        return participants.filterBy('participantValid', true)
    })
})

组件车把

{{targetAudience.title}}: <span class="{{if participantsValid.length '_muted' '_danger'}}">{{participantsValid.length}}</span>

型号:target-audience.js

import DS from 'ember-data'

export default DS.Model.extend({
    title:                       DS.attr('string'),
    singular:                    DS.attr('string'),
    participantsMin:             DS.attr('number'),
    participantsMax:             DS.attr('number'),
    scanGroups:                  DS.hasMany('scanGroup', {async: true}),
    scanParticipants:            DS.hasMany('scanParticipant', {async: true}),
})

型号:scan-participant.js

import DS from 'ember-data'

export default DS.Model.extend({
    hash:           DS.attr('string'),
    opened:         DS.attr('boolean'),
    finished:       DS.attr('boolean'),
    scan:           DS.belongsTo('scan',           {async: true}),
    results:        DS.hasMany('result',           {async: true}),
    participant:    DS.belongsTo('participant',    {async: true}),
    targetAudience: DS.belongsTo('targetAudience', {async: true})
})

型号:partner.js

import DS from 'ember-data'

var inflector = Ember.Inflector.inflector
    inflector.irregular('participant', 'participant')

export default DS.Model.extend({
    name:             DS.attr('string'),
    email:            DS.attr('string'),
    participantValid: Ember.computed('name', 'email', function () {
        // Default vars
        let name  = this.get('name')
        let email = this.get('email')

        // Set validation status
        if((name !== '') && (email !== ''))
            return true;

        return false
    }),
    targetAudiences:  DS.hasMany('targetAudience', {async: true}),

    /**
     * Scans
     */
    scans:            DS.hasMany('scan',            {async: true}),
    scanParticipants: DS.hasMany('scanParticipant', {async: true}),
})

代码已更新为现在的17-02-2016 *

版本信息
Ember:2.1.0
Ember Data:2.1.0
jQuery:1.11.3
Ember Simple Auth:1.0.0

索帕瓜(P. Sopacua)

在花完代码和@ Lux,@ Grapho和@Gaurav的解决方案之后。

花了一个多星期的时间来解决这个错误之后,它终于可以工作了,真正的问题取决于我,我无法弄清楚,因为在工作之后,我尽可能将其改回旧代码,并且在无法正常工作的情况下仍然可以正常工作代码:

组件:scanstart-participants-count.js

import Ember from 'ember'

export default Ember.Component.extend({
    tagName:           'div',
    classNames:        'participant',
    scan:              null,
    targetAudience:    null,

    scanParticipants:  Ember.computed('scan.id', 'targetAudience.scanParticipants.[]', function () {
        // Default properties
        const scanId           = this.get('scan.id')
        const scanParticipants = this.get('targetAudience.scanParticipants')

        // Filter by scan ID.
        return scanParticipants.filterBy('scan.id', scanId)
    }),
    participants:      Ember.computed('scanParticipants.[]', function () {
        // Default properties
        const scanParticipants = this.get('scanParticipants')

        // Map by participant
        return scanParticipants.mapBy('participant')
    }),
    participantsValid: Ember.computed('[email protected]', function () {
        // Default properties
        const participants = this.get('participants')

        // Filter by isValid = true.
        return participants.filterBy('isValid', true)
    })
})

型号:partner.js

import DS from 'ember-data'

var inflector = Ember.Inflector.inflector
    inflector.irregular('participant', 'participant')

export default DS.Model.extend({
    name:    DS.attr('string'),
    email:   DS.attr('string'),

    targetAudiences:  DS.hasMany('targetAudience', {async: true}),

    isValid: Ember.computed('name', 'email', function () {
        // Default vars
        let name  = this.get('name')
        let email = this.get('email')

        // Set validation status
        if((name !== '') && (email !== ''))
            return true;

        return false
    }),
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Laravel广播不会在前端提醒消息

来自分类Dev

VueJS组件不会在前端渲染(可能是Drupal问题)

来自分类Dev

UndoManager的canUndo属性不会在SwiftUI中更新

来自分类Dev

程序永远不会在前台打开

来自分类Dev

聚合物计算的绑定不会在更新时重新计算

来自分类Dev

JProgressBar不会在循环内更新

来自分类Dev

ListView不会在拖放时更新

来自分类Dev

值不会在视图上更新

来自分类Dev

ListView不会在拖放时更新

来自分类Dev

对已挂载的属性的更改不会在VueJS中触发计算

来自分类Dev

聚合物中不会在页面上显示计算的自定义属性

来自分类Dev

Rails:一个属性只会在控制台中更新,而不会在浏览器中更新

来自分类Dev

Kivy Label.text属性不会在用户界面上更新

来自分类Dev

Kivy Label.text属性不会在用户界面上更新

来自分类Dev

绑定到ObservableColellection的ItemsControl不会在属性更改时更新UI

来自分类Dev

通过使用groovy脚本,不会在SOAP UI中更新本地属性值

来自分类Dev

为什么数据中的属性不会在 setInterval 中更新

来自分类Dev

Rails全局变量不会在更新时更新

来自分类Dev

可以在任何位置匹配SSN,而不会在前导或尾随破折号

来自分类Dev

UIPageViewController不会在前台应用程序后重新加载当前的viewController

来自分类Dev

jQuery宽度(%)不会在windowResize上停止计算吗?

来自分类Dev

嵌套属性值不会在EDIT上返回

来自分类Dev

向量层属性不会在函数调用中加载

来自分类Dev

不会在.xhtml中显示bean的属性

来自分类Dev

ng-model不会在IE中更新

来自分类Dev

OnActivityResult不会在Android中更新ImageView

来自分类Dev

angular 2.0 ngClass不会在超时时更新

来自分类Dev

一对多字段不会在JPA中更新

来自分类Dev

EF不会在SaveChanges上更新相关实体

Related 相关文章

  1. 1

    Laravel广播不会在前端提醒消息

  2. 2

    VueJS组件不会在前端渲染(可能是Drupal问题)

  3. 3

    UndoManager的canUndo属性不会在SwiftUI中更新

  4. 4

    程序永远不会在前台打开

  5. 5

    聚合物计算的绑定不会在更新时重新计算

  6. 6

    JProgressBar不会在循环内更新

  7. 7

    ListView不会在拖放时更新

  8. 8

    值不会在视图上更新

  9. 9

    ListView不会在拖放时更新

  10. 10

    对已挂载的属性的更改不会在VueJS中触发计算

  11. 11

    聚合物中不会在页面上显示计算的自定义属性

  12. 12

    Rails:一个属性只会在控制台中更新,而不会在浏览器中更新

  13. 13

    Kivy Label.text属性不会在用户界面上更新

  14. 14

    Kivy Label.text属性不会在用户界面上更新

  15. 15

    绑定到ObservableColellection的ItemsControl不会在属性更改时更新UI

  16. 16

    通过使用groovy脚本,不会在SOAP UI中更新本地属性值

  17. 17

    为什么数据中的属性不会在 setInterval 中更新

  18. 18

    Rails全局变量不会在更新时更新

  19. 19

    可以在任何位置匹配SSN,而不会在前导或尾随破折号

  20. 20

    UIPageViewController不会在前台应用程序后重新加载当前的viewController

  21. 21

    jQuery宽度(%)不会在windowResize上停止计算吗?

  22. 22

    嵌套属性值不会在EDIT上返回

  23. 23

    向量层属性不会在函数调用中加载

  24. 24

    不会在.xhtml中显示bean的属性

  25. 25

    ng-model不会在IE中更新

  26. 26

    OnActivityResult不会在Android中更新ImageView

  27. 27

    angular 2.0 ngClass不会在超时时更新

  28. 28

    一对多字段不会在JPA中更新

  29. 29

    EF不会在SaveChanges上更新相关实体

热门标签

归档