我正在AngularJS中尝试一些特别是设计模型的最佳实践.我认为AngularJS的一个真正的力量是
'当模型更改视图得到更新时,反之亦然'
.这导致了明显的事实
"在任何特定时间,模型都是应用程序状态的唯一真实来源"
现在,在阅读了关于设计正确模型结构的各种博客文章后,我决定使用类似"单一对象"的方法.这意味着整个应用程序状态都保存在一个JavaScript对象中.
例如待办事项
$scope.appState = {
name: "toDoApp",
auth: {
userName: "John Doe",
email: "john@doe.com",
token: "DFRED%$%ErDEFedfereRWE2324deE$%^$%#423",
},
toDoLists: [
{ name: "Personal List",
items: [
{ id: 1, task: "Do something ", dueDate: "2013-01-10 11:56:05", status:"Open", priority : 0},
{ id: 2, task: "Do something ", dueDate: "2013-01-10 11:56:05", status:"Open", priority : 1},
{ id: 3, task: "Do something ", dueDate: "2013-01-10 11:56:05", status:"Open", priority : 0}]
},
{ name: "Work List",
items: [
{ id: …Run Code Online (Sandbox Code Playgroud) javascript model-view-controller model angularjs angularjs-scope
为什么这不起作用?
<input type="file" id="kmlFiles2" multiple onchange="function(){alert('why does this not work')}()">
Run Code Online (Sandbox Code Playgroud)
chrome给我一个错误, Uncaught SyntaxError:Unexpected token(.
Firefox告诉我SyntaxError:function语句需要一个名字.
但这确实有效吗?
<input type="file" id="kmlFiles2" multiple onchange="alert('but this does work')">
Run Code Online (Sandbox Code Playgroud)
我问,因为我正在尝试使用和MVC框架,将代码注入onchange事件.
我目前正在实习,从我一直学习的MVC中的控制器应该仅用于流量,仅用于流量.我也被告知了一个叫做"服务层"的东西,这听起来像是我应该为控制器做任何数据/业务逻辑的地方.
我一直在寻找关于这方面的示例和教程,但我找不到任何让我感到愚蠢的东西,因为我刚刚在一个月前刚学过MVC.我想知道是否有人能够解释并告诉我如何将以下ActionResult Index业务逻辑转移到"服务层".
public class LakerLegendsController : Controller
{
string pathway1 = HostingEnvironment.MapPath(@"~/App_Data/Announcement1.txt");
string pathway2 = HostingEnvironment.MapPath(@"~/App_Data/Announcement2.txt");
string pathway3 = HostingEnvironment.MapPath(@"~/App_Data/Announcement3.txt");
private MoviesEntities db = new MoviesEntities();
public ActionResult Index()
{
// Setting some ViewBag texts from announcement files.
string text1 = System.IO.File.ReadAllText(pathway1);
ViewBag.TextHTML1 = text1;
string text2 = System.IO.File.ReadAllText(pathway2);
ViewBag.TextHTML2 = text2;
string text3 = System.IO.File.ReadAllText(pathway3);
ViewBag.TextHTML3 = text3;
// Following pulls some XML information
XDocument xmlFile = XDocument.Load(@"http://na.leagueoflegends.com/en/rss.xml");
var LoLtitles = from service in xmlFile.Descendants("item")
select …Run Code Online (Sandbox Code Playgroud) model-view-controller asp.net-mvc service-layer asp.net-mvc-5
我尝试了下面的代码,但是当我在浏览器中启动页面时,没有任何东西弹出
<script>
$(function () { //ready
toastr.info('For more information, see our FAQ guide located below.');
});
</script>
Run Code Online (Sandbox Code Playgroud) 我目前正在制作一个在后端共享代码的应用程序.作为表示层,我使用的是WinForms,Cocoa(MonoMac)和GTK#(Linux).
我正在寻找一种以抽象方式描述我的用户界面的方法,因此具体的UI实现(Cocoa,WinForms,GTK#)只需要担心显示和绘图.
这样我就可以 - 从具体视图中连接事件(按钮点击,数据输入)并将它们绑定到控制器/或抽象视图处理程序中的函数. - 让控制器/抽象视图/模型更新视图..?
所以基本上我试图得到一种IView,IController和IModel设置......或者Model-View-Presenter,或MVVM,那里有任何示例应用程序......?因为有很多理论,但没有具体的例子.
对于那些想在LINUX/WINDOWS和MAC上制作桌面跨平台应用程序的人,我建议也考虑一下Electron(electron.atom.io).它基本上是Chromium + NodeJS - 这意味着一个浏览器的UI设计具有Node(和npm包)的强大功能.您还可以通过EdgeJS挂钩.NET代码.
(function () {
var app = angular.module("Sports", []);
var MainController = function($scope, $http) {
var onUser = function (response) {
obj = JSON.parse(response);
$scope.sport = angular.fromJson(obj);
};
$http.get("/api/SportApi/Get").success(function (response) {
obj = JSON.parse(response);
$scope.sport = angular.fromJson(obj);
});
};
app.controller("MainController", ["$scope", "$http", MainController]);
}());
Run Code Online (Sandbox Code Playgroud)
所以,是的,这个脚本不起作用,得到错误它找不到"主控制器作为功能"是什么问题?
编辑:错误原因在于此功能:
function consoleLog(type) {
var console = $window.console || {},
logFn = console[type] || console.log || noop,
hasApply = false;
// Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
// The reason …Run Code Online (Sandbox Code Playgroud) 我有以下路由配置:
routes.MapRoute(
name: "Downloads",
url: "downloads/{filename}",
defaults: new { controller = "Downloads", action = "Index", filename = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
并遵循控制器代码:
public ActionResult Index(string filename)
{ ...
Run Code Online (Sandbox Code Playgroud)
当我用http://test.com/downloads/test.txt调用此Action时,我得到一个404.当我在文件名中调用没有点的Action时,它可以工作.如何让MVC将完整的文件名传递给我的参数文件名?
使用yii2我使用gii创建了一个Model和CRUD.
我想在我的VIEW中使用foreach或while循环以下列格式显示数据
对于数据库表中的每一行
echo("addMarker($lat_field, $lon_field);\n");
Run Code Online (Sandbox Code Playgroud)
我有一个索引页面,使用以下控制器操作呈现.
public function actionIndex()
{
$this->layout = 'directory';
$searchModel = new ShopDirectorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Run Code Online (Sandbox Code Playgroud)
我可以使用以下内容显示数据,使用listview显示数据库中的所有数据/行,但它周围有html,显然不会以我希望的格式输出.
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'col-xs-6 col-sm-3'],
'itemView' => '_index',
]);?>
Run Code Online (Sandbox Code Playgroud)