Вот моя модель нокаута Here is my knockout model

 ///  ///  var data = [ {Id: 1, Name: "Ball Handling" }, {Id: 2, Name: "Shooting" }, {Id: 3, Name: "Rebounding" } ]; function viewModel() { var self = this; self.tags = ko.observableArray(data); self.tagsToAdd = ko.observable(""); self.addTag = function() { self.tags.push({ Name: this.tagsToAdd() }); self.tagsToAdd(""); } } $(document).on("click", ".btn-danger", function () { console.log("inside"); }); var viewModelInstance; function init(){ this.viewModelInstance = new viewModel(); ko.applyBindings(viewModelInstance); } 
+6 +6
источник поделиться source share
4 ответа 4 answers

Похоже, вы уже получили свой первый ответ. Looks like you already got your first answer. На "других способах" привязать событие click, если вы не указали имя класса, существует несколько вариантов. On "other methods", to bind the click event, if you did not specify the class name, there are several options. Вы можете добавить id к тегу и называть его таким образом. You can add id to the tag and call it that way. Или, если вы не хотите добавлять класс или идентификатор, вы можете использовать синтаксис привязки данных со встроенной привязкой "click" для вызова метода на вашей модели представления (очевидно, это не стиль jquery evnet, так что до вас, как вы хотите подключить свои мероприятия). Or, if you do not want to add a class or identifier, you can use the data binding syntax with the built-in "click" binding to call the method on your view model (obviously, this is not the jquery evnet style, so it's up to you how you want to connect your events ) Вот так: Like this:

  
+2 +2
источник source

Вы получаете какие-либо ошибки? Are you getting any errors?

Загрузили ли вы jQuery.js и knockout.js Have you jQuery.js and knockout.js

отправьте код модели просмотра. send view model code.


ах! Oh! у вас есть опечатка you have a typo

 $(document).on("click", ".button-delete", function() { // console.log("inside"; <-- here it is console.log("inside"); }); 

DEMO Demo

+18 +18
источник source
другие ответы other answers

Связанные вопросы Related Questions

6 6
Rails: не может отправить удаленную форму, загруженную через Ajax Rails: cannot submit remote form loaded via Ajax

Похожие вопросы Related questions

7728 7728
Как перенаправить на другую веб-страницу? How to redirect to another web page?
7428 7428
Как проверить, скрыт ли элемент в jQuery? How to check if an element is hidden in jQuery?
4345 4345
Как проверить, установлен ли флажок в jQuery? How to check if checkbox is checked in jQuery?
2817 2817
Как я могу загружать файлы асинхронно? How can I upload files asynchronously?
2628 2628
Как вставить элемент в массив по определенному индексу (JavaScript)? How to insert an element into an array at a specific index (JavaScript)?
2329 2329
Как определить клик вне элемента? How to determine a click outside an element?
2245 2245
Как обновить страницу с помощью jQuery? How to refresh a page using jQuery?
2170 2170
Как получить детей из селектора $(this)? How to get children from the $ (this) selector?
1898 1898
$ (document). $ (document). уже эквивалент без jQuery already equivalent without jQuery
1194 1194
window.onload vs $(document).ready() window.onload vs $ (document) .ready ()

Наир сначала сообщит мне, что вы хотите сделать здесь если вы хотите удалить кнопку, работает. Nair first tells me what you want to do here if you want to remove the button, it works. затем используйте функцию удаления jquery Ui, и если вы хотите что-то консоль, то просто напишите console.log( "вы хотите консоль" ); then use the jquery Ui delete function, and if you want something console, then just write console.log ("you want a console");

Я думаю, что ваша строка function() { console.log("inside"; }); is wrong I think your line is function() { console.log("inside"; }); is wrong function() { console.log("inside"; }); is wrong . function() { console.log("inside"; }); is wrong .

0 0
источник source

Я бы рекомендовал вам взглянуть на привязку клика для нокаута, а не на смешивание нокаута со случайным запросом. I would recommend that you take a look at the click binding for a knockout, rather than mixing a knockout with a random request. Связывание кликов позволит вам привязать событие click к функции в модели представления. Linking clicks allows you to bind the click event to a function in the view model.

0 0
источник source

Посмотрите другие вопросы по меткам или Задайте вопрос See other questions about tags or Ask a Question

👨🏿‍🔬 ☘️ 🌗
undefined

Source: https://habr.com/ru/post/908758/


All Articles