<tfoot id='Rnvf7'></tfoot>
        <i id='Rnvf7'><tr id='Rnvf7'><dt id='Rnvf7'><q id='Rnvf7'><span id='Rnvf7'><b id='Rnvf7'><form id='Rnvf7'><ins id='Rnvf7'></ins><ul id='Rnvf7'></ul><sub id='Rnvf7'></sub></form><legend id='Rnvf7'></legend><bdo id='Rnvf7'><pre id='Rnvf7'><center id='Rnvf7'></center></pre></bdo></b><th id='Rnvf7'></th></span></q></dt></tr></i><div id='Rnvf7'><tfoot id='Rnvf7'></tfoot><dl id='Rnvf7'><fieldset id='Rnvf7'></fieldset></dl></div>

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

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

      1. <legend id='Rnvf7'><style id='Rnvf7'><dir id='Rnvf7'><q id='Rnvf7'></q></dir></style></legend>

      2. 骨干关系事件未触发?

        Backbone relational events not firing?(骨干关系事件未触发?)

          <tbody id='KhyLf'></tbody>

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

                1. <tfoot id='KhyLf'></tfoot>
                  <i id='KhyLf'><tr id='KhyLf'><dt id='KhyLf'><q id='KhyLf'><span id='KhyLf'><b id='KhyLf'><form id='KhyLf'><ins id='KhyLf'></ins><ul id='KhyLf'></ul><sub id='KhyLf'></sub></form><legend id='KhyLf'></legend><bdo id='KhyLf'><pre id='KhyLf'><center id='KhyLf'></center></pre></bdo></b><th id='KhyLf'></th></span></q></dt></tr></i><div id='KhyLf'><tfoot id='KhyLf'></tfoot><dl id='KhyLf'><fieldset id='KhyLf'></fieldset></dl></div>
                  <legend id='KhyLf'><style id='KhyLf'><dir id='KhyLf'><q id='KhyLf'></q></dir></style></legend>

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

                2. 本文介绍了骨干关系事件未触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  class TheModel extends Backbone.RelationalModel
                      relations:[
                          type: Backbone.HasMany
                          key: 'subModels'
                          relatedModel: SubModel
                          collectionType: SubModels
                          reverseRelation:
                              key: 'TheModel'
                      ]
                  
                  themodel = new the TheModel({subModels:[{#stuff},{#stuff},{#stuff}]})
                  

                  我有 createModels 所以 themodel.get('subModels') 返回模型的集合.

                  I have createModels on so themodel.get('subModels') returns a collection of models.

                  现在,如果我将更改的子模型数据传递到 mymodel

                  Now if I pass changed subModel data into mymodel

                  themodel.set({subModels:[{changedstuff},{stuff},{stuff}]})
                  

                  themodel 不应该抛出 change 事件吗?它不适合我.

                  Shouldn't themodel throw a change event? It doesn't for me.

                  如果我将相同的数据传递给 mymodel

                  More so if I pass identical data into mymodel

                  themodel.set({subModels:[{samestuff},{samestuff},{samestuff}]})
                  

                  themodel.attributes.subModels 会引发 addupdate 事件,即使没有什么是新的.

                  themodel.attributes.subModels throws add and update events, even though nothing is new.

                  我不确定为什么会出现这些问题,任何帮助都会很棒,谢谢!!!!

                  I'm not sure why these issues are happening, any help would be great, thanks!!!!

                  推荐答案

                  如果你通过设置一个新集合来重置整个关系,Backbone-relational 将(目前)只是替换整个集合,而不是检查差异.所以它会为所有当前的 subModels 触发 remove 事件,然后为每个新的 add 事件触发.

                  If you reset a whole relation like that by setting a new collection, Backbone-relational will (at the moment) just replace the whole collection, instead of checking for differences. So it'll fire a remove event for all current subModels, then fire add events for each new one.

                  我确实收到了 change 事件,使用以下代码(如果发布的代码包含完整的示例,这将有所帮助;)

                  I do get change events though, with the following code (it would help if posted code contains a complete example though ;)

                  var SubModel = Backbone.RelationalModel.extend({});
                  
                  var TheModel = Backbone.RelationalModel.extend({
                      relations: [{
                          type: Backbone.HasMany,
                          key: 'subModels',
                          relatedModel: SubModel,
                          reverseRelation: {
                              key: 'TheModel'
                          }
                      }]
                  });
                  
                  themodel = new TheModel({subModels: [{ id: 5 },{id: 7},{id: 8}]})
                  
                  themodel.bind( 'change', function() {
                          console.debug( 'change; args=%o', arguments );
                      });
                  themodel.bind( 'change:subModels', function() {
                          console.debug( 'change:subModels; args=%o', arguments );
                      });
                  themodel.bind( 'update:subModels', function() {
                          console.debug( 'update:subModels; args=%o', arguments );
                      });
                  themodel.bind( 'add:subModels', function() {
                          console.debug( 'add:subModels; args=%o', arguments );
                      });
                  themodel.bind( 'remove:subModels', function() {
                          console.debug( 'remove:subModels; args=%o', arguments );
                      }); 
                  
                  
                  console.debug( 'set new subModels' );
                  themodel.set( {subModels: [{ id: 5 },{id: 7},{id: 9}] } )
                  

                  这会产生以下输出:

                  set new subModels
                  change:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, [Object { id=5}, Object { id=7}, Object { id=9}], Object {}]
                  change; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, undefined]
                  remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
                  remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
                  remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
                  add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
                  add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
                  add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
                  update:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
                  

                  如果您没有看到这些更改事件,您能否检查一下您正在使用哪些版本的主干和主干关系?

                  If you don't see these change events, could you check which versions of backbone and backbone-relational you're using?

                  这篇关于骨干关系事件未触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在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中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                3. <i id='0IndB'><tr id='0IndB'><dt id='0IndB'><q id='0IndB'><span id='0IndB'><b id='0IndB'><form id='0IndB'><ins id='0IndB'></ins><ul id='0IndB'></ul><sub id='0IndB'></sub></form><legend id='0IndB'></legend><bdo id='0IndB'><pre id='0IndB'><center id='0IndB'></center></pre></bdo></b><th id='0IndB'></th></span></q></dt></tr></i><div id='0IndB'><tfoot id='0IndB'></tfoot><dl id='0IndB'><fieldset id='0IndB'></fieldset></dl></div>
                    • <bdo id='0IndB'></bdo><ul id='0IndB'></ul>
                      <legend id='0IndB'><style id='0IndB'><dir id='0IndB'><q id='0IndB'></q></dir></style></legend>

                          • <small id='0IndB'></small><noframes id='0IndB'>

                          • <tfoot id='0IndB'></tfoot>

                              <tbody id='0IndB'></tbody>