简体   繁体   English

KnockoutJS-选择下拉列表绑定不起作用

[英]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. 我正在研究一个项目,该项目使用敲除构建CRUD系统,并通过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. 我创建了一个jsfiddle http://jsfiddle.net/rqwku4kb/20/来演示该问题。 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. (1)获得可观察到的currentIncident的值,然后将其丢弃。 It's always null and never set so this is doubly redundant. 它始终为null且从不设置,因此这是双重冗余。 (2) Reference an undefined variable called chosen_composante which does not exist in IncidentList . (2)引用一个未定义的变量chosen_composante ,该变量在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 我无法为您解决此问题,因为我不确定要去哪里,但是应该足以使您走上正轨-您混淆了IncidentList和Incident的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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