javascript - Ember.js: Data is being cleared from my fixtures array depending on how it is accessed -
i have 2 controllers. first, keywordsindexcontroller looks this:
app.keywordsindexcontroller = em.arraycontroller.extend({ contentbinding: "app.keyword.fixtures" });
...the other, keywordsnewcontroller blank arraycontroller:
app.keywordsnewcontroller = em.controller.extend({ });
i have 2 views, keywordsindexview , keywordsnewview each have function in them. keywordsindexcontroller in charge of listing keywords , deleting single keyword. keywordsnewcontroller responsible adding new keyword routing list of keywords (index). this:
app.keywordsindexview = em.view.extend({ templatename: 'templates/keywords/index', delkeyword: function(e){ var obj = app.keyword.fixtures.findproperty("name", e._data.attributes.name); app.keyword.fixtures.removeobject(obj); } }); ---------------------------------------- app.keywordsnewview = em.view.extend({ templatename: 'templates/keywords/new', addkeyword: function(){ app.keyword.fixtures.pushobject({ id: app.keyword.length, name: newkey.value, scode: '55678', campaign: null }); this.get('controller.target.router').transitionto('keywords.index'); } });
the issue
both of these events work on own expected. if go straight new keyword page works beautifully. issue arises when visit keywords list page before trying add together new keyword. when go through route these errors when tries add together new keyword:
uncaught typeerror: cannot phone call method 'hasownproperty' of undefined uncaught typeerror: cannot read property 'name' of undefined
additionally, when seek print out app.keyword.fixtures array comes empty class.
i not sure cause behavior , thoughts/help much appreciated.
extra credit
in testing environment (i.e. fixtures) there improve way reference object other "app.keyword.fixtures"?
thanks!
in testing environment (i.e. fixtures) there improve way reference object other "app.keyword.fixtures"?
use app.keyword.all()
in model
method of route:
model: function(controller){ homecoming app.keyword.all(); }
this live array updated if models added later.
also, don't force objects fixtures
, utilize createrecord
create new object:
app.keyword.createrecord({ id: app.keyword.length, name: newkey.value, scode: '55678', campaign: null });
javascript arrays binding ember.js fixtures
No comments:
Post a Comment