knockout.js 关于用于嵌套的数组无关系的foreach多层嵌套报undefined的错误

问题描述:

我要实现ko的foreach多层嵌套,用于foreach的两个数组没有关系,第二层foreach绑定的数组报错:
Message: Unable to process binding "foreach: function (){return p2 }"
Message: p2 is not defined

代码:

js:
viewModel = {

p1 : ko.observableArray(
[
{ firstName: 'Bert', lastName: 'Bertington' },
{ firstName: 'Charles', lastName: 'Charlesforth' },
{ firstName: 'Denise', lastName: 'Dentiste' }
]
),
p2 : ko.observableArray(
[
{ firstName: 'Bert', lastName: 'Bertington' },
{ firstName: 'Charles', lastName: 'Charlesforth' },
{ firstName: 'Denise', lastName: 'Dentiste' }
]
),
}

html:

<div data-bind="foreach:p1">
    <div>我是p1</div>
    <div data-bind="foreach:p2">
        <li>我是p2</li>
    </div>
</div>
报错:

knockout-3.2.0.debug.js:2890 Uncaught ReferenceError: Unable to process binding "foreach: function (){return p1 }"
Message: Unable to process binding "foreach: function (){return p2 }"
Message: p2 is not defined
    at foreach (eval at createBindingsStringEvaluator (knockout-3.2.0.debug.js:2503), <anonymous>:3:60)
    at knockout-3.2.0.debug.js:3739
    at Object.init (knockout-3.2.0.debug.js:4859)
    at init (knockout-3.2.0.debug.js:3764)
    at knockout-3.2.0.debug.js:2867
    at Object.ignore (knockout-3.2.0.debug.js:1194)
    at knockout-3.2.0.debug.js:2866
    at Object.arrayForEach (knockout-3.2.0.debug.js:121)
    at applyBindingsToNodeInternal (knockout-3.2.0.debug.js:2852)
    at applyBindingsToNodeAndDescendantsInternal (knockout-3.2.0.debug.js:2732)

请各位大牛帮忙看看。
谢谢。



Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
从AJAX调用中加载knock中的knockout.js形式

<div class="post-text" itemprop="text"> <p>I'm attempting to load some HTML stored as text for a knockout.js form. A customer's server will use an AJAX GET call to my server which will then return the HTML for the table. Right now, the table is being returned, however it's formatted like knockout.js hasn't been loaded but I'm not receiving any errors (dropdown not populated, foreach loop for a table is displaying a blank row, a secondary div is displayed when it should only be displayed once a submit button has been pressed). </p> <p>When I have the HTML on this page it works, so I'm pretty sure it's not incorrect code in the form. The only thing I can think of is that knockout is picky about single and double quotes, although I feel like that would rsult in errors. Right now I'm testing on my server so same origin policy shouldn't be an issue at the moment. </p> <p>Here is the page that initially loads</p> <pre><code>//main.html &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" &gt;&lt;/script&gt; &lt;!-- I also tried to include the knockout file includes here but made no difference --&gt; &lt;script&gt; &lt;!-- call to get HTML for knockout form --&gt; $.ajax({ type: 'GET', url: '/orders/return_form', data: "true", success: function(response) { // on success.. $('#order_div').html(response); // update the DIV } }) &lt;/script&gt; &lt;div id = "order_div"&gt; &lt;!-- returned knockout form goes here --&gt; &lt;/div&gt; &lt;script src="knockout.js"&gt;&lt;/script&gt; &lt;script src="knockout_info.js"&gt;&lt;/script&gt; &lt;!-- MVVM file --&gt; &lt;script src = "Knockout-Validation/Src/knockout.validation"&lt;/script&gt; </code></pre> <p>Here is the code to return the code for the table</p> <pre><code>//orders/return_form if($_GET['true']){ echo "table code here "; //I tried to encode this before but got all kinds of extra markup due to whitespace and other misc. characters //or $form = new stdClass; $form-&gt;table = "&lt;form method='post'&gt; &lt;input type='textbox' name='text'/&gt; &lt;input type='submit' name='textsubmit'/&gt; &lt;/form&gt;"; echo $form-&gt;table; } </code></pre> <p>If I include the table instead of calling for the code it works. However, it's a pretty lengthy form and considering this code will be on someone else's server calling to mine, I'd like to keep their code to a minimum.</p> </div>

现在有什么比knockout.js还高效的 json 调用框架

我在很久以前,调用处理json数据使用的而是json框架,现在这么多年过去了,有没有什么更好的框架取代了knockout.js。

knockout的if语句该怎么写

有两个div 如何利用knockout.js中的if流程语句控制它们的显示

knockout.js绑定触发问题

使用了click绑定用于点击地址查询操作,现在想进入页面直接进行一次查询,能不能让click绑定在进入页面的时候也触发一次?

从每个元素的二维数组中提取子数组,并使用KnockoutJS在表中显示它们

<div class="post-text" itemprop="text"> <p>I have used below code in PHP to extract data from MySQL :</p> <pre><code>&lt;?php require("connect.php"); $sql = "SELECT `inn_lay_list`, `inner_layer` FROM `da_customer_auto_inner` where `mpcode` = 'qf017'"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_assoc($result)) { $data1 = $row['inn_lay_list']; $data2 = $row['inner_layer']; } $parts1 = explode(';',$data1); $parts2 = explode(';',$data2); $layer_cnt = count($parts1); $array_inner = array_chunk($parts2, 8); echo json_encode($parts1); echo json_encode($array_inner); mysqli_close($conn); ?&gt; </code></pre> <p>I obtained the result as:</p> <p>["001","011","021","031"]</p> <p>[["1","2","3","4","5","6","7","8"], ["11","12","13","14","15","16","17","18"], ["21","22","23","24","25","26","27","28"],[31","32","33","34","35","36","37","38"]]</p> <p>Here for each element in first array there is a sub array in the second array(two dimensional array). Now I want to display this in HTML page using a table. I am trying to use KnockoutJS “foreach” option with a named template:</p> <pre><code>&lt;script&gt; function MyViewModel() { this.layer = [{ name: "&lt;?=@$parts1[0]?&gt;", layer_data: "&lt;?=@$array_inner[0]?&gt;" }, { name: "&lt;?=@$parts1[1]?&gt;", layer_data: "&lt;?=@$array_inner[1]?&gt;" }, { name: "&lt;?=@$parts1[2]?&gt;", layer_data: "&lt;?=@$array_inner[2]?&gt;" }, { name: "&lt;?=@$parts1[3]?&gt;", layer_data: "&lt;?=@$array_inner[3]?&gt;" }] } ko.applyBindings(new MyViewModel()); &lt;/script&gt; &lt;table class="table table-bordered"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Layer&lt;/td&gt; &lt;td&gt;P2P&lt;/td&gt; &lt;td&gt;P2T&lt;/td&gt; &lt;td&gt;T2T&lt;/td&gt; &lt;td&gt;Track Width&lt;/td&gt; &lt;td&gt;PTH To Cu&lt;/td&gt; &lt;td&gt;NPTH To Cu&lt;/td&gt; &lt;td&gt;PTH AR&lt;/td&gt; &lt;td&gt;Via AR&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody data-bind="template:{name:'layer-template', foreach:layer}"&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;script type="text/html" id="layer-template"&gt; &lt;tr&gt; &lt;td data-bind="text: name"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[0]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[1]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[2]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[3]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[4]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[5]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[6]"&gt;&lt;/td&gt; &lt;td data-bind="text: layer_data[7]"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/script&gt; </code></pre> <p>I want my output as below :</p> <p><a href="https://i.stack.imgur.com/8ScGG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8ScGG.png" alt="Output"></a></p> </div>

knockout.js easyui .net 问题

<input type="text" data-bind="datasource:dataSource.productbatch,combobox:pageData.form.productbatch,Value:pageData.form.productBatchNo" id="baseid" class="z-txt easyui-combobox" /> 这种封装到knockout.js的easyui的下拉框怎么获取值啊,用easyui的方法获取不到

发送javascript变量(从knockout.js)到php并返回结果

<div class="post-text" itemprop="text"> <p>How can I go about accomplishing the following behavior.</p> <ol> <li><p>upon getting an input from a knockout.js form send the variable to a page to be handled. The page uses PHP</p></li> <li><p>The PHP page receives the input from the knockout.js form and runs some calculations and then returns the result</p></li> <li><p>The variable is then received back on the original page and is then displayed via knockout</p></li> </ol> <p>For example, say I have the following</p> <pre><code>//knockout_form.js self.addItem = function() { var itemNum = self.newItem; //variable received from knockout form var returnedVariable = ???? **send itemNum to processing.php which will then return it** self.itemNumbers.push(new ItemEntry(retunredVariable, "$20.00")); // } </code></pre> <p>I know that jQuery/Ajax can be used to post to processing.php, but how do I return the calculated data from processing.php back to the javascript page?</p> <p><strong>edit below. The data appears to be sent to processing.php (shows up in the network tab) but the alert isn't showing.</strong></p> <pre><code>// Operations self.addItem = function() { var itemNum = self.newItem; $.getJSON("processing.php?itemNum=" + itemNum),function(data) { alert(data); //this does not appear self.itemNumbers.push(new ItemEntry(data.result, "$20.00")); } } </code></pre> <p>Here's the php </p> <pre><code>//$result = $_GET['itemNum']; $result = "test"; //set it just to be sure it's working echo json_encode(array("result" =&gt; $result)); </code></pre> </div>

JS控件如何给Knockout参数赋值

``` > 1. <input data-bind="value: EndDate, visible: editMode" id='date' onclick="laydate()" /> > ``` 其中EndDate为knockout的ko.observerable()的参数 ; onclick为JS时间控件 求解为什么无法给EndDate赋值?

从外部视图模型中调用knockout.js中的函数

<div class="post-text" itemprop="text"> <p>I'm using CakePHP 2.3.8 and I'm trying to call a function from within a knockout.js view model, but I'm having some trouble understanding what's going on. </p> <p>If a specific variable is set (in PHP), then I want to display a div but I'm having trouble getting it to work. When I call it from the PHP code, the div doesn't display, however an alert message from within the method triggers so I know that code is being reached.</p> <pre><code>&lt;div data-bind = "visible: someDiv"&gt; I'm visible &lt;/div&gt; </code></pre> <p>Here's the knockout viewmodel</p> <pre><code>function myViewModel(){ var self = this; self.someDiv = ko.observable(false); //the div starts out hidden self.editing = ko.observable(false); //if the editing variable is changed, display someDiv self.editing.subscribe(function(){ alert('edit changed'); //this alert triggers every time, even from the PHP call self.someDiv(true); //someDiv only shows if I call from within the view model }); //if I manually change editing to true from within the viewmodel, the div shows //self.editing(true); } ko.applyBindings(new myViewModel()); </code></pre> <p>Here's the PHP code that initiates the sequence of events</p> <pre><code>echo $this-&gt;Html-&gt;script('knockout-2.3.0'); echo $this-&gt;Html-&gt;script('viewmodel'); //if the edit variable is set, the "someDiv" should be set to true if(isset($edit)){ &lt;script&gt; window.vm = new myViewModel(); window.vm.editing(true); //this will trigger the alert from the subscribe function, but the div doesn't display &lt;/script&gt; } </code></pre> <p>Why is it when I change the editing value to true from PHP the div doesn't display, but if I change it from within the viewmodel it displays?</p> <p>Is it even possible to do what I'm attempting?</p> <p><strong>Edit</strong></p> <p>I am applying bindings to my viewmodel in that JS file. I am <strong>not</strong> applying bindings again in the PHP file.</p> <p>What I mean from "variable is set (in PHP)" is that the source of the data originates from PHP, although it is JavaScript setting the value in the end. I kept it short for my example above, so really it would be like this (not that it makes much of a difference)</p> <pre><code>//if the edit variable is set, the "someDiv" should be set to true if(isset($edit)){ &lt;script&gt; window.vm = new myViewModel(); window.vm.editing(&lt;?php echo $edit; ?&gt;); //this will trigger the alert from the subscribe function, but the div doesn't display window.vm.another(&lt;?php echo $something_else_here; ?&gt;); &lt;/script&gt; } </code></pre> </div>

使用knockout.js和CakePHP失败的GET请求

<div class="post-text" itemprop="text"> <p>I'm incorporating paypal into my site , however, once I receive the token and try to redirect to paypal's site, nothing happens. I'm using knockout.js on my front end. When I click a button to make a GET request, the values are sent over to a corresponding CakePHP action which verifies the data and then redirect to paypal's site to finish the transaction. </p> <p>Now here's the strange part. At first I assumed I messed up the jQuery to make the GET but that doesn't seem to be the case. When I make the GET request with the header('location...') code included in the corresponding action, the network tab shows the request failed as "canceled". However, when I comment out the header('location..') code the request goes through successfully.</p> <p>Here's GET request on</p> <pre><code>//order_processing.js $.getJSON("/orders/pay_for_order/" + itemNumbers + "/" + quantities + "/" + prices + "/" + productNames + "/" + self.fullName() + "/" + self.addressLine1() + " " + self.addressLine2() + "/" + self.city() + "/" + self.state() + "/" + self.ZIP() + "/" + self.email(),function(data) { }); </code></pre> <p>Here's the action that the request goes to</p> <pre><code>//OrdersController function pay_for_order($id = null){ //processing code here //get token from paypal if($finalize_order-&gt;verifyPrice($item_numbers, $prices) == TRUE){ //when I comment out this header redirect the GET request is successful, but of course then does not redirect header( 'Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&amp;token='.$token ) ; } } </code></pre> <p>I know my calls to paypal are working correctly to get the token, because when I copy/paste the link into the address bar it then redirects (meaning the token was successfully received). This to me seems like it's an issue with jQuery making the request. However, I'm confused as to why the GET request fails when I have the header redirect included, but when it's commented out the GET passes. </p> <p><strong>Update</strong></p> <p>I swapped out the header redirect for the following and it doesn't fail, however, it doesn't redirect either. This code showing up in the response as well, so I think this probably means CakePHP does not like header('location') redirects. </p> <pre><code>echo '&lt;META HTTP-EQUIV="Refresh" Content="0; URL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&amp;token='.$token.'"&gt;'; </code></pre> </div>

使用knockout.js在第二页滑块上获取第一页输入值

<div class="post-text" itemprop="text"> <p>I have a 2 pages, first page with a form </p> <pre><code>&lt;form action="index.php/moneyexchange/save_userinput" method="post"&gt; &lt;input type="text" placeholder="Amount in &amp;euro;"&gt; &lt;a type="submit" style="background-color:#fff; color:#66cccc;" href="&lt;?php echo base_url();?&gt;index.php/money/firstpage"&gt;Borrow&lt;/a&gt; &lt;/form&gt; </code></pre> <p>And in the second page I have a slider using KNOCKOUT JS functionality.</p> <pre><code>&lt;input id="ex2" data-slider-id="ex2Slider" type="text" data-bind="sliderValue: {value: amount, min:0, max: 5000, step: 1, tooltip: 'always', formatter:formatter2}" style="display: none;"&gt; </code></pre> <p>What I want to do is get the Amount value from the first page and show it on the knockout js sliders. Right now I am showing in the sliders a value of 2500.</p> <pre><code>self.amount = ko.observable(2500); var amount = ko.observable(2500); self.formatter1 = function(amount) { return amount + ' kk'; } </code></pre> <p>Can someone help me in how to get the value from the first page and add to the observable of second page so the sliders start with that value. Thanks for the help. I dont mind if I can even bring the data from cookies, but what I am trying to do normally right now is load this data, to codeigniter controller like this,</p> <pre><code>public function save_userinput(){ $this-&gt;load-&gt;helper('form'); $form_data = $this-&gt;input-&gt;post(); } </code></pre> <p>And then initialize it in the knockout js File which I have, but I need a proper way of doing it.</p> </div>

Knockout Js功能没有出现在页面上

<div class="post-text" itemprop="text"> <p>I have a js file named admin.js which has knockout js functionality.</p> <pre><code>function AppViewModel() { var self = this; self.alldata = ko.observableArray(); self.viewAllInvoice = function() { $.ajax({ type: 'POST', url: BASEURL + 'index.php/main/learn_Ko/', contentType: 'application/json; charset=utf-8' }) .done(function(invoices) { alert("hello"); self.alldata.removeAll(); $.each(invoices, function(index, invoice) { self.alldata.push(invoice); }); }) .fail(function(xhr, status, error) { alert(status); }) .always(function(data) {}); }; self.viewAllInvoice(); } $(document).ready(function() { ko.applyBindings(new AppViewModel(), document.getElementById('loanersclub_wrapper')); }); </code></pre> <p>I am trying to call the function in this page like this.</p> <pre><code>&lt;script type="text/javascript" src="&lt;?php echo base_url();?&gt;js/admin.js" &gt;&lt;/script&gt; &lt;div style="margin-top:30px;" class="container" id="loanersclub_wrapper" class="wrapper"&gt; &lt;h1&gt;HELLo&lt;/h1&gt; &lt;/div&gt; &lt;div class="table-responsive"&gt; &lt;table class="table table-striped table-bordered table-condensed"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="text-center"&gt;1&lt;/th&gt; &lt;th class="text-center"&gt;2&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody data-bind="foreach: alldata"&gt; &lt;tr&gt; &lt;td class="text-center"&gt;&lt;span data-bind="text: $data.Loantime "&gt;&lt;/span&gt;&lt;/td&gt; &lt;td class="text-center"&gt;&lt;span data-bind="text: $data.Amount"&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>The thing is that, I am getting this data from a controller since I am using php, and I checked the controller does get the information as arrays, but the js file is not getting any thing, I even tried using alert, but seems like the function self.viewAllInvoice is not getting called at all.</p> </div>

如何在knockoutjs中的html文件中使用动态可观察变量名

<div class="post-text" itemprop="text"> <p>I am using knockjs and I have created dynamic observableArrays in js file. Ex. <code>product+productid</code> which creates a dynamic observableArrays as <code>product123</code>.</p> <p>I want to use this in a data bind foreach loop and want to create this variable dynamically again in html file.</p> <p>Something like : <code>data-bind="foreach: { data: "product"+product.id()()}</code></p> <p>So this <code>"product"+product.id()()</code> binding should call my product123() array.</p> <p>How can I achieve this?</p> </div>

knockout级联绑定下拉框问题

网页中,如何利用Knockout.js把如下结构的json绑定到两个下拉框中,显示是CategoryName,value是CategoryId,父级变,子级下拉框跟着变,请大侠直接告诉我解决方案好吗? ``` [ { "ParentCategory": { "CategoryId": "a70b2eb0-483e-4bb7-a3da-4d80ab48d94f", "CategoryName": "类别A", }, "SubCategoryList": [ { "CategoryId": "2f8b3dbb-62c3-4955-8f4c-432d858164a0", "CategoryName": "A子类1", }, { "CategoryId": "a94064c9-6176-4f22-8564-c59505f7b431", "CategoryName": "A子类2", }, { "CategoryId": "b4b0b176-57a1-4f6c-9758-254eb3a30171", "CategoryName": "A子类3", } ] }, { "ParentCategory": { "CategoryId": "05163221-d053-4469-86e2-5725fc00d759", "CategoryName": "类别B", }, "SubCategoryList": [ ] } ] ```

Knockout.js AJAX获取

<div class="post-text" itemprop="text"> <p>I am new to using Knockout.js and for that matter JavaScript as well. I went through their tutorials and tried to modify the example to load data from server as below. Can anyone please point what's wrong with my code</p> <p>JavaScript:</p> <pre><code>jQuery(document).ready(function () { MyViewModel = function() { var self =this; self.name = ko.observable(""); self.getJson = function() { jQuery.ajax({ //Do all the work success: function(data) { self.name = data.name; } }); } } myViewModelObj = new MyViewModel(); ko.applyBindings(myViewModelObj); myViewModelObj.getJson(); }); </code></pre> <p>View:</p> <pre><code> &lt;h1 data-bind="text: name "&gt;&lt;/h1&gt; </code></pre> </div>

在 AngularJS 中数据绑定是如何工作的?

<div class="post-text" itemprop="text"> <p>How does data binding work in the <code>AngularJS</code> framework?</p> <p>I haven't found technical details on <a href="http://angularjs.org" rel="noreferrer">their site</a>. It's more or less clear how it works when data is propagated from view to model. But how does AngularJS track changes of model properties without setters and getters?</p> <p>I found that there are <a href="https://stackoverflow.com/questions/1029241/javascript-object-watch-for-all-browsers">JavaScript watchers</a> that may do this work. But they are not supported in <a href="http://en.wikipedia.org/wiki/Internet_Explorer_6" rel="noreferrer">Internet Explorer 6</a> and <a href="http://en.wikipedia.org/wiki/Internet_Explorer_7" rel="noreferrer">Internet Explorer 7</a>. So how does AngularJS know that I changed for example the following and reflected this change on a view?</p> <pre><code>myobject.myproperty="new value"; </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/9682092/how-does-data-binding-work-in-angularjs</p>

使用knock out js不显示从ajax请求滚动获得的数据

<div class="post-text" itemprop="text"> <p>I have used a code that I got from a site for infinite scrolling using knockout js, with some changes in it.</p> <p>Here's my html and javascript code:</p> <pre><code>&lt;div id="main" data-bind="foreach: items, event: { scroll: scrolled }"&gt; &lt;div data-bind="text: name"&gt;&lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var viewModel = { items: ko.observableArray([]), scrolled: function(data, event) { var elem = event.target; if (elem.scrollTop &gt; (elem.scrollHeight - elem.offsetHeight - 200)) { getItems(6); } }, maxId: 0, pendingRequest: ko.observable(false) }; function getItems(cnt) { if (!viewModel.pendingRequest()) { var entries = []; for (var i = 0; i &lt; cnt; i++) { var id = viewModel.maxId++; entries.push({ id: id }); } viewModel.pendingRequest(true); $.ajax({ type: 'POST', url: 'echojson.php', data: { json: ko.toJSON(entries), delay: .1, id:id, cnt:cnt }, success: function(entries) { ko.utils.arrayForEach(entries, function(entry) { alert(entry); viewModel.items.push(entry); }); viewModel.pendingRequest(false); }, error: function() { viewModel.pendingRequest(false); }, dataType: 'json' }); } } ko.applyBindings(viewModel); getItems(6); &lt;/script&gt; </code></pre> <p>And here is the php file code from where I am getting the data:</p> <pre><code>&lt;?php include 'dbconfig.php'; $jsonarr=json_decode($_POST['json'],true); $cnt=$_POST['cnt']; if(isset($_POST['id'])){ $offset=$_POST['id']; } if($offset&lt;=$cnt){ $offset=0; } else{ $offset=$offset-($cnt-1); } $json=array(); $sql="SELECT * FROM user LIMIT $offset,".$cnt; $exec=mysqli_query($con,$sql); while($row=mysqli_fetch_array($exec)){ $name=strtoupper($row['fname'].' '.$row['lname']); $profilepic=$row['profilepic']; $city=$row['city']; $json[]=$name.' '.$profilepic.' '.$city; } echo json_encode($json); ?&gt; </code></pre> <p>On scroll, I get the correct number of div added but the data in <code>items</code> array is not displayed in the div with id <code>main</code>. </p> <p>When I alert elements in array items, I do get the values in it. But this updated array is not getting binded to the div it seems.</p> <p>Please help me fix this.</p> </div>

淘汰赛ViewModel更新

<div class="post-text" itemprop="text"> <p>I am new to Knockout and I am trying to update my ViewModel from an ajax call. <br> This is what I have right now: <br><br> <strong>LoanDeductions.js</strong></p> <pre><code>var deductionLine = function (deductionID, deductionName, amount) { self = this; self.deductionID = ko.observable(deductionID); self.deductionName = ko.observable(deductionName); self.amount = ko.observable(amount); }; function LoanDeductions(deductions) { var self = this; self.loanDeductions = ko.observableArray(ko.utils.arrayMap(deductions, function (deduction) { return new deductionLine(deduction.deductionID, deduction.deductionName, deduction.amount) })); // Operationss self.removeLine = function (line) { self.loanDeductions.remove(line) }; }; </code></pre> <p>and this is my scripts in my view:</p> <pre><code> @section scripts { &lt;script src="~/Scripts/koModel/LoanDeductions.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var updateValues = function () { $.ajax({ 'url': '@Url.Action("UpdateDeductionValues","LoanApp")', 'data': { amount: $('.LoanAmount').val() }, 'success': function (result) {// update viewmodel scripts here} }); var viewModel = new LoanDeductions(@Html.Raw(Model.CRefLoansDeductions2.ToJson())); $(document).ready(function () { ko.applyBindings(viewModel); $('.datepicker').datepicker(); $('.LoanAmount').change(function () { updateValues(); }; }); }); &lt;/script&gt; } </code></pre> <p>So, in my view, I have a dropdown list with class name "LoanAmount" which when value is changed, it will perform an ajax call, send the selected loanAmount value to the server, recompute the deduction amounts, <strong>then the server returns a jsonresult that looks like this</strong>:</p> <pre><code>"[{\"deductionID\":1,\"deductionName\":\"Loan Redemption Fee\",\"amount\":53.10},{\"deductionID\":2,\"deductionName\":\"Document Stamp\",\"amount\":9.00}]" </code></pre> <p>Now what I wanted to do is use this json data as my new viewModel. <br> Can anyone show me the way how to do this, please note that I manually mapped my viewmodel and didn't used the ko mapping plugin. <br> Any help will be greatly appreciated. Thank you, more power! <br> <br> <strong>EDIT (in response to Fabio)</strong></p> <pre><code>function updateData() { $.ajax({ url: '@Url.Action("UpdateDeductionValues","LoanApp")', data: { amount: self.selectedLoanAmount() }, success: function (deductions) { //load your array with ko.utils.arrayMap ko.utils.arrayMap(deductions, function (deduction) { return new deductionLine(deduction.deductionID, deduction.deductionName, deduction.amount) }); } }); } </code></pre> </div>

使用AJAX和PHP永久存储注释[关闭]

<div class="post-text" itemprop="text"> <p>I have written a POST and GET function in javascript to send comments from input and to retrieve stored comments whenever the page is loaded. However I don't know how to handle the data that I send, how do I handle it after the data is sent to save it and then on a later point be able to access it again after a reload? So in short, send comments to server, then retrieve them on a new pageload. </p> <p>I was thinking of making a storage.php file where I would handle the data and then put it to a file, but i'm not quite sure how it would work. </p> <p>Here are the POST and GET functions:</p> <pre><code> self.getEntries=function(){ $.ajax({ type:"GET", url:"storage.php", dataType:'json', data: jsonData, success: function(data){ vm.comments=data.comments; } }); } self.sendEntry=function(){ $.ajax({ type:"POST", url:"storage.php", dataType:'json', data: jsonData }); var jsonData=ko.toJSON(ViewModel); </code></pre> <p>Any help or examples would be very helpful! Thanks in advance. :)</p> </div>

Python可以这样学(第一季:Python内功修炼)

董付国系列教材《Python程序设计基础》、《Python程序设计(第2版)》、《Python可以这样学》配套视频,讲解Python 3.5.x和3.6.x语法、内置对象用法、选择与循环以及函数设计与使用、lambda表达式用法、字符串与正则表达式应用、面向对象编程、文本文件与二进制文件操作、目录操作与系统运维、异常处理结构。

获取Linux下Ftp目录树并逐步绑定到treeview

在linux下抓取目录树,双击后获取该节点子节点(逐步生成)。另外有两个类,一个是windows下的(一次性获取目录树),一个是linux下的(足部获取目录树)

NS网络模拟和协议仿真源代码

NS网络模拟和协议仿真源代码,包含代码说明及协议分析

简单的NS3网络模拟仿真(计算机网络作业)

简单的NS3网络模拟仿真,内附有PPT演示。论文评述。以及简单的安装教程。

手把手实现Java图书管理系统(附源码)

【超实用课程内容】 本课程演示的是一套基于Java的SSM框架实现的图书管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的java人群。详细介绍了图书管理系统的实现,包括:环境搭建、系统业务、技术实现、项目运行、功能演示、系统扩展等,以通俗易懂的方式,手把手的带你从零开始运行本套图书管理系统,该项目附带全部源码可作为毕设使用。 【课程如何观看?】 PC端:https://edu.csdn.net/course/detail/27513 移动端:CSDN 学院APP(注意不是CSDN APP哦) 本课程为录播课,课程2年有效观看时长,大家可以抓紧时间学习后一起讨论哦~ 【学员专享增值服务】 源码开放 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化

三个项目玩转深度学习(附1G源码)

从事大数据与人工智能开发与实践约十年,钱老师亲自见证了大数据行业的发展与人工智能的从冷到热。事实证明,计算机技术的发展,算力突破,海量数据,机器人技术等,开启了第四次工业革命的序章。深度学习图像分类一直是人工智能的经典任务,是智慧零售、安防、无人驾驶等机器视觉应用领域的核心技术之一,掌握图像分类技术是机器视觉学习的重中之重。针对现有线上学习的特点与实际需求,我们开发了人工智能案例实战系列课程。打造:以项目案例实践为驱动的课程学习方式,覆盖了智能零售,智慧交通等常见领域,通过基础学习、项目案例实践、社群答疑,三维立体的方式,打造最好的学习效果。

150讲轻松搞定Python网络爬虫

【为什么学爬虫?】 &nbsp; &nbsp; &nbsp; &nbsp;1、爬虫入手容易,但是深入较难,如何写出高效率的爬虫,如何写出灵活性高可扩展的爬虫都是一项技术活。另外在爬虫过程中,经常容易遇到被反爬虫,比如字体反爬、IP识别、验证码等,如何层层攻克难点拿到想要的数据,这门课程,你都能学到! &nbsp; &nbsp; &nbsp; &nbsp;2、如果是作为一个其他行业的开发者,比如app开发,web开发,学习爬虫能让你加强对技术的认知,能够开发出更加安全的软件和网站 【课程设计】 一个完整的爬虫程序,无论大小,总体来说可以分成三个步骤,分别是: 网络请求:模拟浏览器的行为从网上抓取数据。 数据解析:将请求下来的数据进行过滤,提取我们想要的数据。 数据存储:将提取到的数据存储到硬盘或者内存中。比如用mysql数据库或者redis等。 那么本课程也是按照这几个步骤循序渐进的进行讲解,带领学生完整的掌握每个步骤的技术。另外,因为爬虫的多样性,在爬取的过程中可能会发生被反爬、效率低下等。因此我们又增加了两个章节用来提高爬虫程序的灵活性,分别是: 爬虫进阶:包括IP代理,多线程爬虫,图形验证码识别、JS加密解密、动态网页爬虫、字体反爬识别等。 Scrapy和分布式爬虫:Scrapy框架、Scrapy-redis组件、分布式爬虫等。 通过爬虫进阶的知识点我们能应付大量的反爬网站,而Scrapy框架作为一个专业的爬虫框架,使用他可以快速提高我们编写爬虫程序的效率和速度。另外如果一台机器不能满足你的需求,我们可以用分布式爬虫让多台机器帮助你快速爬取数据。 &nbsp; 从基础爬虫到商业化应用爬虫,本套课程满足您的所有需求! 【课程服务】 专属付费社群+每周三讨论会+1v1答疑

cuda开发cutilDLL

包括cutil32.dll、cutil32D.dll、cutil32.lib、cutil32D.lib,以及附带的glew32.lib/freeglut.lib

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

Tensorflow与python3.7适配版本

tensorflow与python3.7匹配的最新库,更新了python3.7以后可以自行下载,或者去国外python的扩展包下载界面自行下载。

4小时玩转微信小程序——基础入门与微信支付实战

这是一个门针对零基础学员学习微信小程序开发的视频教学课程。课程采用腾讯官方文档作为教程的唯一技术资料来源。杜绝网络上质量良莠不齐的资料给学员学习带来的障碍。 视频课程按照开发工具的下载、安装、使用、程序结构、视图层、逻辑层、微信小程序等几个部分组织课程,详细讲解整个小程序的开发过程

专为程序员设计的数学课

<p> 限时福利限时福利,<span>15000+程序员的选择!</span> </p> <p> 购课后添加学习助手(微信号:csdn590),按提示消息领取编程大礼包!并获取讲师答疑服务! </p> <p> <br> </p> <p> 套餐中一共包含5门程序员必学的数学课程(共47讲) </p> <p> 课程1:《零基础入门微积分》 </p> <p> 课程2:《数理统计与概率论》 </p> <p> 课程3:《代码学习线性代数》 </p> <p> 课程4:《数据处理的最优化》 </p> <p> 课程5:《马尔可夫随机过程》 </p> <p> <br> </p> <p> 哪些人适合学习这门课程? </p> <p> 1)大学生,平时只学习了数学理论,并未接触如何应用数学解决编程问题; </p> <p> 2)对算法、数据结构掌握程度薄弱的人,数学可以让你更好的理解算法、数据结构原理及应用; </p> <p> 3)看不懂大牛代码设计思想的人,因为所有的程序设计底层逻辑都是数学; </p> <p> 4)想学习新技术,如:人工智能、机器学习、深度学习等,这门课程是你的必修课程; </p> <p> 5)想修炼更好的编程内功,在遇到问题时可以灵活的应用数学思维解决问题。 </p> <p> <br> </p> <p> 在这门「专为程序员设计的数学课」系列课中,我们保证你能收获到这些:<br> <br> <span> </span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">①价值300元编程课程大礼包</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">②应用数学优化代码的实操方法</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">③数学理论在编程实战中的应用</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">④程序员必学的5大数学知识</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">⑤人工智能领域必修数学课</span> </p> <p> <br> 备注:此课程只讲程序员所需要的数学,即使你数学基础薄弱,也能听懂,只需要初中的数学知识就足矣。<br> <br> 如何听课? </p> <p> 1、登录CSDN学院 APP 在我的课程中进行学习; </p> <p> 2、登录CSDN学院官网。 </p> <p> <br> </p> <p> 购课后如何领取免费赠送的编程大礼包和加入答疑群? </p> <p> 购课后,添加助教微信:<span> csdn590</span>,按提示领取编程大礼包,或观看付费视频的第一节内容扫码进群答疑交流! </p> <p> <img src="https://img-bss.csdn.net/201912251155398753.jpg" alt=""> </p>

实现简单的文件系统

实验内容: 通过对具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。 要求: 1.在内存中开辟一个虚拟磁盘空间作为文件存储器,在其上实现一个简

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

四分之一悬架模型simulink.7z

首先建立了四分之一车辆悬架系统的数学模型,应用MATLAB/Simulink软件建立该系统的仿真模型,并输入路面激励为随机激励,控制不同的悬架刚度和阻尼,选用最优的参数得到车辆悬架的振动加速度变化曲线

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

C++语言基础视频教程

C++语言基础视频培训课程:本课与主讲者在大学开出的程序设计课程直接对接,准确把握知识点,注重教学视频与实践体系的结合,帮助初学者有效学习。本教程详细介绍C++语言中的封装、数据隐藏、继承、多态的实现等入门知识;主要包括类的声明、对象定义、构造函数和析构函数、运算符重载、继承和派生、多态性实现等。 课程需要有C语言程序设计的基础(可以利用本人开出的《C语言与程序设计》系列课学习)。学习者能够通过实践的方式,学会利用C++语言解决问题,具备进一步学习利用C++开发应用程序的基础。

Java8零基础入门视频教程

这门课程基于主流的java8平台,由浅入深的详细讲解了java SE的开发技术,可以使java方向的入门学员,快速扎实的掌握java开发技术!

HoloLens2开发入门教程

本课程为HoloLens2开发入门教程,讲解部署开发环境,安装VS2019,Unity版本,Windows SDK,创建Unity项目,讲解如何使用MRTK,编辑器模拟手势交互,打包VS工程并编译部署应用到HoloLens上等。

C/C++学习指南全套教程

C/C++学习的全套教程,从基本语法,基本原理,到界面开发、网络开发、Linux开发、安全算法,应用尽用。由毕业于清华大学的业内人士执课,为C/C++编程爱好者的教程。

pokemmo的资源

pokemmo必须的4个rom 分别为绿宝石 火红 心金 黑白 还有汉化补丁 资源不错哦 记得下载

test_head.py

本文件主要是针对使用dlib的imglab标注工具标记的目标检测框和关键点检测而生成的xml文件, 转换为coco数据集格式.

Java面试史上最全的JAVA专业术语面试100问 (前1-50)

前言: 说在前面, 面试题是根据一些朋友去面试提供的,再就是从网上整理了一些。 先更新50道,下一波吧后面的也更出来。 求赞求关注!! 废话也不多说,现在就来看看有哪些面试题 1、面向对象的特点有哪些? 抽象、继承、封装、多态。 2、接口和抽象类有什么联系和区别? 3、重载和重写有什么区别? 4、java有哪些基本数据类型? 5、数组有没有length()方法?String有没有length()方法? 数组没有length()方法,它有length属性。 String有length()方法。 集合求长度用

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

linux“开发工具三剑客”速成攻略

工欲善其事,必先利其器。Vim+Git+Makefile是Linux环境下嵌入式开发常用的工具。本专题主要面向初次接触Linux的新手,熟练掌握工作中常用的工具,在以后的学习和工作中提高效率。

DirectX修复工具V4.0增强版

DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复

20行代码教你用python给证件照换底色

20行代码教你用python给证件照换底色

2019 Python开发者日-培训

本次活动将秉承“只讲技术,拒绝空谈”的理念,邀请十余位身处一线的Python技术专家,重点围绕Web开发、自动化运维、数据分析、人工智能等技术模块,分享真实生产环境中使用Python应对IT挑战的真知灼见。此外,针对不同层次的开发者,大会还安排了深度培训实操环节,为开发者们带来更多深度实战的机会。

我以为我对Mysql事务很熟,直到我遇到了阿里面试官

太惨了,面试又被吊打

相关热词 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行 c# 循环给数组插入数据 c# 多线程死锁的例子 c# 钉钉读取员工排班 c# label 不显示 c#裁剪影像 c#工作进程更新ui
立即提问