<legend id='DlksP'><style id='DlksP'><dir id='DlksP'><q id='DlksP'></q></dir></style></legend>
    <tfoot id='DlksP'></tfoot>

    <small id='DlksP'></small><noframes id='DlksP'>

    • <bdo id='DlksP'></bdo><ul id='DlksP'></ul>

    1. <i id='DlksP'><tr id='DlksP'><dt id='DlksP'><q id='DlksP'><span id='DlksP'><b id='DlksP'><form id='DlksP'><ins id='DlksP'></ins><ul id='DlksP'></ul><sub id='DlksP'></sub></form><legend id='DlksP'></legend><bdo id='DlksP'><pre id='DlksP'><center id='DlksP'></center></pre></bdo></b><th id='DlksP'></th></span></q></dt></tr></i><div id='DlksP'><tfoot id='DlksP'></tfoot><dl id='DlksP'><fieldset id='DlksP'></fieldset></dl></div>
    2. 更新数组时不会触发模型的更改事件?

      Model#39;s change event won#39;t fire when updating an array?(更新数组时不会触发模型的更改事件?)
      <i id='m6d1x'><tr id='m6d1x'><dt id='m6d1x'><q id='m6d1x'><span id='m6d1x'><b id='m6d1x'><form id='m6d1x'><ins id='m6d1x'></ins><ul id='m6d1x'></ul><sub id='m6d1x'></sub></form><legend id='m6d1x'></legend><bdo id='m6d1x'><pre id='m6d1x'><center id='m6d1x'></center></pre></bdo></b><th id='m6d1x'></th></span></q></dt></tr></i><div id='m6d1x'><tfoot id='m6d1x'></tfoot><dl id='m6d1x'><fieldset id='m6d1x'></fieldset></dl></div>
      <legend id='m6d1x'><style id='m6d1x'><dir id='m6d1x'><q id='m6d1x'></q></dir></style></legend>

              <bdo id='m6d1x'></bdo><ul id='m6d1x'></ul>
                <tbody id='m6d1x'></tbody>
              <tfoot id='m6d1x'></tfoot>

              1. <small id='m6d1x'></small><noframes id='m6d1x'>

                本文介绍了更新数组时不会触发模型的更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                使用backbone.js...

                Using backbone.js...

                @model.bind 'change', ()-> console.log 'updated'
                
                addIndex = (index) =>
                    array = @model.get('array')
                    array.push index
                    @model.set
                        array: array
                

                这会完美地更新模型,但不会触发更改事件.有谁知道我发布的内容为什么?

                This updates the model perfectly but doesn't trigger the change event. Does anyone know why from looking at what I posted?

                我添加了这个,它触发了更改事件:

                I added this and it triggers the change event:

                @model.set
                    test: ''
                
                num = 0
                setInterval ()=>
                    num++
                    @model.set
                    test: num
                , 3000
                

                我添加了这个,它不会触发更改事件:

                I added this and it doesn't trigger the change event:

                @model.set
                    test: []
                
                num = 0
                setInterval ()=>
                    console.log 'testupdate'
                    num++
                    test = @model.get('test')
                    test.push num
                    @model.set
                        test: test
                , 3000
                

                推荐答案

                Brian 关于原因的回答太棒了!

                Brian's answer as to the reason is awesome!

                想要提供另一种方法来获得你想要的东西,而不是把它清空或克隆数组.

                Wanted to present another way to get what you want instead of nulling it out or cloning the array.

                只需自己手动触发更改:

                Just manually trigger the change yourself:

                addIndex = (index) =>
                    array = @model.get('array')
                    array.push index
                    @model.trigger('change:array',@model, array)
                

                这篇关于更新数组时不会触发模型的更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                <i id='CYhMb'><tr id='CYhMb'><dt id='CYhMb'><q id='CYhMb'><span id='CYhMb'><b id='CYhMb'><form id='CYhMb'><ins id='CYhMb'></ins><ul id='CYhMb'></ul><sub id='CYhMb'></sub></form><legend id='CYhMb'></legend><bdo id='CYhMb'><pre id='CYhMb'><center id='CYhMb'></center></pre></bdo></b><th id='CYhMb'></th></span></q></dt></tr></i><div id='CYhMb'><tfoot id='CYhMb'></tfoot><dl id='CYhMb'><fieldset id='CYhMb'></fieldset></dl></div>
                • <bdo id='CYhMb'></bdo><ul id='CYhMb'></ul>
                • <small id='CYhMb'></small><noframes id='CYhMb'>

                • <legend id='CYhMb'><style id='CYhMb'><dir id='CYhMb'><q id='CYhMb'></q></dir></style></legend>
                        <tbody id='CYhMb'></tbody>
                        <tfoot id='CYhMb'></tfoot>