[英]Knockout observable property is not updating
I am using knockout.js plugin in my application.我在我的应用程序中使用knockout.js 插件。 I have a problem with observable.
我有一个可观察的问题。 I created an Example Fiddle .
我创建了一个Example Fiddle 。 In this fiddle i am creating
Menus
dynamically and generating Menu sequence
each time when new menu is added.在这个小提琴中,我正在动态创建
Menus
并在每次添加新菜单时生成Menu sequence
。 User can to delete any existing menu also except first one.用户也可以删除任何现有菜单,除了第一个。
The problem comes when user delete any existing menu.当用户删除任何现有菜单时就会出现问题。 Because at the time of deletion i am updating the sequence number in the remove function but the sequence numbers are not updating.
因为在删除时我正在更新删除函数中的序列号,但序列号没有更新。 Can anybody please tell me whats the problem ?
有人可以告诉我有什么问题吗?
Modified:修改的:
newMenuVM.Sequence = ko.observable(self.menus().length+1);
self.menus()[i].Sequence(i+1);
Deleted:删除:
self.courseOptions.push(newMenuVM);
Reason:原因:
When I run your fiddle, I see an error "Property 'Sequence' of object # is not a function".当我运行你的小提琴时,我看到一个错误“对象 # 的属性‘序列’不是函数”。
I search this property and see:我搜索这个属性,看到:
newMenuVM.Sequence = self.menus().length+1;
So, I add ko.observable function.所以,我添加了ko.observable函数。
You are redefining the Sequence variable.您正在重新定义 Sequence 变量。 Originally it is a ko.observable.
最初它是一个 ko.observable。 You are setting it to a integer value.
您将其设置为整数值。 You should set the value as so
你应该这样设置值
newMenuVM.Sequence(self.menus().length+1);
This will allow the observable to notify and update the value on screen.这将允许 observable 通知和更新屏幕上的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.