我需要backbone.js吗?(Is backbone.js necessary for me?)
我正在开发一个webapp,最近我发现了backbone.js。 现在我正在开始一个新的应用程序,正在考虑学习backbone.js。 通过制作音乐播放器的3部分截屏教程,我只有1/3,而我的印象是模型和视图的设置非常混乱和乏味。 我正在开发PHP / Codeigniter框架,所以我想我已经知道MVC将如何帮助我。
但是,如果我想开发一个单页(多个标签)应用程序说,对于商店所有者来管理他们的库存,它可以使用显示仪表板,库存,供应,销售,助手,商店分支的选项卡。 如果没有backbone.js,jQuery的服务器端后端是不是足够了? jQuery可以隐藏显示不同的选项卡视图,处理UI元素的交互,发送和检索AJAX调用,管理模式对话框......当我可以使用数组时,为什么要使用集合和视图? 在这种情况下,使用backbone.js如何帮助开发此应用程序?
backbone.js has caught my interest recently as I was developing a webapp. Now I am starting a new app and is considering learning about backbone.js. I'm 1/3 of the way through a 3 part screencast tutorial on making a music player and my impressions are that the setting up of models and views were quite confusing and tedious. I am developing in PHP/Codeigniter framework so I guess I have an idea of how MVC will help me.
But if I want to develop an single page (multiple tabs) app say, for store owners to manage their inventory, it can uses tabs that shows Dashboard, Inventory, Supplies, Sales, Assistants, Store Branches. Wouldn't a serverside backend with jQuery be sufficient without backbone.js? jQuery can hide display the different tab views, handle the interaction of UI elements, send and retrieve AJAX calls, manage modal dialogs... Why should I use collections and views when I can use arrays? In this case, how will using backbone.js help in developing this app?
原文:https://stackoverflow.com/questions/10980210
最满意答案
首先,你需要修改你的php脚本 :
echo "<li><a class='clsPostData' data-sensorid='".$result['oxi_sensorid']."' data-apikey='".$result['oxi_apikey']."' href='#'>".$local."</a></li>";
和你的JQuery代码:
$(function(){ $('.clsPostData').click(function(e){ e.preventDefault(); var objPost = {}; objPost.api = $(this).data('apikey'); objPost.sensor = $(this).data('sensorid'); $.ajax({ url: 'getData.php', type: 'post', data: objPost }).done(function(responseFromPhp){ //Do something with the response, like alert(responseFromPhp.message); }); }); });
你的getData.php脚本:
<?php $apikey = $_POST["api"]; $sensorid = $_POST["sensor"]; $response["message"] = "Grettings from php, we receive your sensorid: ".$sensorid; echo json_encode($response); ?>
First, you need to modify your php script:
echo "<li><a class='clsPostData' data-sensorid='".$result['oxi_sensorid']."' data-apikey='".$result['oxi_apikey']."' href='#'>".$local."</a></li>";
And your Jquery code:
$(function(){ $('.clsPostData').click(function(e){ e.preventDefault(); var objPost = {}; objPost.api = $(this).data('apikey'); objPost.sensor = $(this).data('sensorid'); $.ajax({ url: 'getData.php', type: 'post', data: objPost }).done(function(responseFromPhp){ //Do something with the response, like alert(responseFromPhp.message); }); }); });
Your getData.php script:
<?php $apikey = $_POST["api"]; $sensorid = $_POST["sensor"]; $response["message"] = "Grettings from php, we receive your sensorid: ".$sensorid; echo json_encode($response); ?>
相关问答
更多-
如何将数据属性添加到wordpress导航菜单中的
- 元素(how to add data attribute to a
- element in wordpress nav menu)
[2022-02-06]我不确定WP是否有针对此的特定过滤器/方法。 您将不得不与wp_nav_menu_items一起进行一些手动DOM操作。 https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/ function addDataAttr( $items, $args ) { $dom = new DOMDocument(); $dom->loadHTML($items); $find = $dom->getElementsB ... -
取消你的样式规则的右边填充为#sidebar .menu a ...应该读取padding:10px 0而不是padding:10px 40px take off the left right padding of your style rule for #sidebar .menu a ... should read padding:10px 0 instead of padding:10px 40px
-
当你说which tag is right menu ul li or menu li? ,你是在谈论一个class="menu"的div吗?或者你在谈论不赞成使用的菜单标记 (
-
首先,你需要修改你的php脚本 : echo "
- ".$local."
"; 和你的JQuery代码: $(function(){ $('.clsPostData').click(function(e){ e.preventDe ... -
在处理提交的文件中使用$_SERVER['HTTP_REFERER'] 。 Use $_SERVER['HTTP_REFERER'] in the file you process the submission.
-
尝试添加jour图片作为标签的背景。 也适用于标签的样式。 a { width: 16.66%; height: 100px; display: block; background: url(your image URL); background-position: center; background-size: cover; background-repeat: none; } 背景尺寸:封面; 拉伸图像,直到它填满您的内容框。 您还可以使用不同 ...
-
出来选择它: .page-header .menu li a.active, .page-header .menu li a.active:hover { background-color: white; font-weight: bold; color:black; } http://jsfiddle.net/userdude/RSwnP/ 注意,我已经添加了a.active:hover ,但是注意选择器特异性在这里覆盖了它。 看一下这个小提琴的例子(你可能想也可能不想用),其中 ...
-
CSS UL / LI菜单不居中(CSS UL/LI menu not centering)[2023-09-03]
为menu提供宽度并使用margin: auto; #menu{ width:300px; <--------Here margin: 0 auto; <-----Here padding: 5px 0 0 0; list-style: none; background-color:#333333; text-align:center; } 而且你为什么要这样做? #menu li:hover > ul{ display: block; } 还有这 ... -
将li移至菜单右侧(Move li to the right in menu)[2022-06-14]
首先: #nav { display: table; width: 100%; } .alignright { float: right; } First of all: #nav { display: table; width: 100%; } .alignright { float: right; } -
https://api.jquery.com/parent/ $(“li”)。parent(“。level3 dropdown-menu dynamic”)。addClass(“dropdown-submenu”); 是对的吗? Well, after some test with your code mHenderson, I finally got the answer! $(function () { $("ul.level3").parent("").addClass("d ...