简体   繁体   中英

KnockoutJS - Select dropdown binding not working

Im working on a project to build a CRUD system using knockout and getting and saving my data via AJAX. Been having issues binding the select dropdown. When I try to edit an incident I get the following error:

Uncaught TypeError: Cannot read property 'push' of undefined

I created a jsfiddle http://jsfiddle.net/rqwku4kb/20/ to demonstrate the issue. I'm still working on the delete and add a new incident link so they are not working yet but im working on that seperately.

Here is the code that`s causing me issues at the moment.

self.ShowMeTheCurrentSelectedIncident = function(data) {
    self.currentIncident();
    self.chosen_composante.push([data.Composante]);
};

Would anyone have have any idea where the issue might be or be able to provide me some advice?

The method here is what's wrong:

self.ShowMeTheCurrentSelectedIncident = function(data) {
        self.currentIncident(); // (1)
        self.chosen_composante.push([data.Composante]); // (2)
    };

What this does:

(1) get the value of the observable currentIncident and then throw it away. It's always null and never set so this is doubly redundant. (2) Reference an undefined variable called chosen_composante which does not exist in IncidentList .

I could not fix this for you since I wasn't sure what values were to go where, but it should be enough to set you on the right track - you're confusing the properties of the IncidentList and Incident

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM